So I just started reading about serialization of class and how I can save them into a binary file. But after I define my class as <serializable()> and try to save the object it keeps throwing me this exception.

"An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll

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


My class is about 1000 lines of code so I won't post it as it contains information from other modules so it will be hard to figure out what i'm doing. My class basically consists of dynamic labels, checkboxes and arrays of each labels and checkboxes. I have several functions and also added handlers for the array checkboxes and events for the checkboxes.

I'm not sure that because mostly all my controls are dynamic serialization won't work.Please help me out as this would be easier than manually trying to get all the information of class(object) 7 times.

Member Avatar for Unhnd_Exception

See if this works.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim ClassToSerialize As New SerializeTestClass("Shauntay")
        Dim ClassSerializer As New System.Xml.Serialization.XmlSerializer(GetType(SerializeTestClass))
        Dim ClassMemoryStream As New System.IO.MemoryStream

        ClassSerializer.Serialize(ClassMemoryStream, ClassToSerialize)

        ClassMemoryStream.Position = 0

        Dim DerSerializedClass As SerializeTestClass = ClassSerializer.Deserialize(ClassMemoryStream)

    End Sub


<Serializable()> _
Public Class SerializeTestClass

    Private fpName As String

    Property Name() As String
        Get
            Return fpName
        End Get
        Set(ByVal value As String)
            fpName = value
        End Set
    End Property

    Sub New()

    End Sub

    Sub New(ByVal Name As String)
        fpName = Name
    End Sub

End Class

Unhnd_Exception this is the class I'm dealing with. Sorry about not putting enough comments as this project was not meant to be coded with other programmers. I don't think it might be possible to serialize :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.