I'm trying to serialize the main class in my VB solution. I've added the Serializable attribute at the top of my class like so:
<Serializable()>
Public Class Form1
and I'm using the following code to serialize:
Public Sub serializeThis()
Dim fStream As FileStream
Try
fStream = New FileStream("C:\ObjectData.bin", FileMode.Create)
Dim bfmtr As New BinaryFormatter
bfmtr.Serialize(fStream, Me)
fStream.Close()
Catch ex As Exception
MsgBox("Failed to serialize: " & ex.Message)
Throw
End Try
End Sub
When I call this method I'm getting the error:
Type 'System.Windows.Forms.Form' in Assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
I'm guessing this is because you can't serialize the form that is attached to the class or something, but I really don't know what I'm doing.
Can I serialize all of the objects contained in my Form1 class somehow, without getting this error? I don't want to store any data about the form controls, I just need to save all the objects that I've defined at the top of the Form1
class.
Thanks for any help.