[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?
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.