Results 1 to 2 of 2

Thread: [RESOLVED] [2005] Error using BinaryFormatter

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Resolved [RESOLVED] [2005] Error using BinaryFormatter

    I am trying to serialize a class to a file using the BinaryFormatter. I keep getting this error:

    "Type 'System.Windows.Forms.UserControl' in Assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."

    and I don't know why. The class makes no reference to any user control, or form. This class is a property of a user control, but I don't see why that would be an issue. The class is in its own project with no reference to System.Windows.Forms.

    Does anyone have any idea why I would be getting this error?


    I just found what is causing the errors. It's because of 2 custom events. How can I serialize the object and keep the events?
    Last edited by mpdeglau; Oct 2nd, 2006 at 01:50 PM.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] Error using BinaryFormatter

    Found the solution. It turns out that because of the way vb implements Events, when you try to serialize the class containing the events it will try and serialize the form these events are on, which is not possible. I got a solution here.

    The article talks about the possibilty of being able to mark events as nonserializable in the "next version" of vb, which by looking at the date would be 2005. Does anyone know if this is possible? I tried to do it a couple of ways, but couldn't figure it out, if it is possible now.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width