none
WndProc(Message& m) - is not marked as serializable RRS feed

  • Question

  • I was asked in the Word forum to ask this here.

    I set the following in my AddIn to log uncaught exceptions:

    System.Windows.Forms.Application.ThreadException += Application_ThreadException;

    And we have a case where we are getting the following exception:

    System.Runtime.Serialization.SerializationException: Type 'Laserfiche.OfficePlugin.SaveToLaserfiche.MessageFilter' in Assembly 'Laserfiche.Word2010Plugin, Version=8.3.0.0, Culture=neutral, PublicKeyToken=607dd73ee2bd1c00' is not marked as serializable.
       at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
       at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
       at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
       at System.Runtime.Remoting.RemotingServices.MarshalToBuffer(Object o)
       at System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(IntPtr pUnk)
       at System.Windows.Forms.Application.ThreadContext.get_ComponentManager()
       at System.Windows.Forms.Application.ThreadContext.FormActivated(Boolean activate)
       at System.Windows.Forms.Form.WmActivate(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at DevExpress.XtraEditors.XtraForm.WndProc(Message& msg)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Which leads to three questions:

      • Our AddIn is not Laserfiche - is there anything we can/should do to avoid this problem? Or is it something Laserfiche needs to do?
      • What do they need to do?
      • Is there a way to get the call stack above NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)? So we can wrap our code that leads to this in a try/catch?

    thanks - dave


    Who will win The International Collegiate Programming Championships?

    Monday, October 22, 2012 4:21 PM

Answers

  • Hi Dave,

    This is something the third party will need to investigate further, however, regarding your first question, I can say generally that serialization is required any time an object is marshaled across threads.  It sounds like the third party may not have dealt with that contingency but are now encountering it with your message filter.

    Regarding the second question, I may not fully understand the scenario, but if you are getting an exception during the underlying call to the native WndProc, have you tried simply wrapping a try/catch block around base.WndProc call?  I believe that should let you catch any subsequent exception that occurs.  But catching and eating exceptions that are not expected is universally a bad idea, since they will most often lead to subsequent unexpected behavior.  If you know of this specific exception and that it is safe to handle, you should catch it explicitly and otherwise simply allow any other exceptions to bubble up and cause a failure immediately.

    If you still are encountering the issue and this is something Microsoft can help with (which may not be the case in fact, since the third party may need to address an issue in their control), this may require a deeper investigation than we can undertake in a simple forum post.  In that case, please open a support incident with us and we will pursue it further as necessary.  If you can isolate the issue outside of the third party control and reproduce it, then that may allow us to eliminate any questions about their implementation also.

    Thank you.

    Jon Burchel

    • Marked as answer by DavidThi808 Thursday, November 8, 2012 6:17 PM
    Thursday, November 8, 2012 5:52 PM

All replies

  • Our AddIn is not Laserfiche - is there anything we can/should do to avoid this problem? Or is it something Laserfiche needs to do?

    You can of course put this question to Laserfiche. But, before that, if Laserfiche is used as a member or it is used inside a property, then mark that member/property as Non-Serializable.

    Is there a way to get the call stack above NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)? So we can wrap our code that leads to this in a try/catch?

    Did you try to use 'InnerException' property of the exception object caught in ThreadException event handler? I mean e.Exception.InnerException.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Mike FengModerator Wednesday, October 24, 2012 1:22 PM
    • Unproposed as answer by DavidThi808 Wednesday, October 24, 2012 2:12 PM
    Monday, October 22, 2012 5:27 PM
  • Hi Dave,

    Do you have any update?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, October 24, 2012 1:23 PM
    Moderator
  • Wednesday, October 24, 2012 2:30 PM
  • Hi Mike;

    Nope, we've hit a brick wall. We're trying to get Laserfiche to respond but so far we just keep getting pointed to different people.


    Who will win The Windward International Collegiate Programming Championships?

    Wednesday, October 24, 2012 2:30 PM
  • Hi David,

    The error message is "

    Type 'Laserfiche.OfficePlugin.SaveToLaserfiche.MessageFilter' in Assembly 'Laserfiche.Word2010Plugin, Version=8.3.0.0, Culture=neutral, PublicKeyToken=607dd73ee2bd1c00' is not marked as serializable.

    So did you try to mark it as serializable: http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, October 30, 2012 11:05 AM
    Moderator
  • Hi Mike;

    That's what we're asking Laserfiche to do.

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Tuesday, October 30, 2012 1:26 PM
  • Hi David,

    Sorry I don't understand you very well.

    >>That's what we're asking Laserfiche to do.

    Do you mean you use Laserfiche to serialize something?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, October 31, 2012 5:02 AM
    Moderator
  • Hi Mike;

    Yes, Laserfiche wrote the Add-In that throws the exception. Since the bug is in their code, we need them to fix it. Very weird that Windows requires their method to be serialized though - it must be in a distinct app domain.

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Wednesday, October 31, 2012 1:23 PM
  • Hi David,

    The Laserfiche is this: http://www.laserfiche.com ?

    Right?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 1, 2012 6:29 AM
    Moderator
  • Hi Mike;

    Yep, that Laserfiche. They're working through their process to get the issue to their developers.

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Thursday, November 1, 2012 12:24 PM
  • Hi David,

    Since the tool is a third party library, I suggest you ask this question on the official site:http://www.laserfiche.com/en-us/Events . As Adavesh stated, this tool is not supported in this forum.

    Thank you for your understanding and support.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, November 5, 2012 7:18 AM
    Moderator
  • Mike;

    My questions, which I think are appropiate for this forum, are:

    1. When does a message pump filter have to be serialized?
    2. Is there anything our app can do to avoid this issue? ie, can we work around their bug?

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Monday, November 5, 2012 1:56 PM
  • Hi David,

    The exception occurs during serialization or deserialization: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationexception.aspx  there is no particular scenario.

    Since I have little knowledge about this tool, I have no workaround about this.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, November 5, 2012 2:31 PM
    Moderator
  • Hi Mike;

    Let me rephrase the questions:

    1. I am writing an AddIn for Word. I am going to place a filter on the message pump. Do I need to serialize the class that I place on the message pump? Under what conditions do I need to do this (as I have an AddIn that watches the message pump, is not serialized, and works fine)?
    2. How can I write my message pimp filter so that if anything else in the filter chain throws an exception, it does not cause my AddIn to die?

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Monday, November 5, 2012 2:53 PM
  • Hi Dave,

    This is something the third party will need to investigate further, however, regarding your first question, I can say generally that serialization is required any time an object is marshaled across threads.  It sounds like the third party may not have dealt with that contingency but are now encountering it with your message filter.

    Regarding the second question, I may not fully understand the scenario, but if you are getting an exception during the underlying call to the native WndProc, have you tried simply wrapping a try/catch block around base.WndProc call?  I believe that should let you catch any subsequent exception that occurs.  But catching and eating exceptions that are not expected is universally a bad idea, since they will most often lead to subsequent unexpected behavior.  If you know of this specific exception and that it is safe to handle, you should catch it explicitly and otherwise simply allow any other exceptions to bubble up and cause a failure immediately.

    If you still are encountering the issue and this is something Microsoft can help with (which may not be the case in fact, since the third party may need to address an issue in their control), this may require a deeper investigation than we can undertake in a simple forum post.  In that case, please open a support incident with us and we will pursue it further as necessary.  If you can isolate the issue outside of the third party control and reproduce it, then that may allow us to eliminate any questions about their implementation also.

    Thank you.

    Jon Burchel

    • Marked as answer by DavidThi808 Thursday, November 8, 2012 6:17 PM
    Thursday, November 8, 2012 5:52 PM
  • Ok, thanks. That across threads is I think the key item to pass on to Laserfiche. And I think you're right, that there is no way to eat their exception safely.

    thanks - dave


    Who will win The Windward International Collegiate Programming Championships?

    Thursday, November 8, 2012 6:18 PM