Hello,

I'm trying to create a custom control that contains a List(Of Panel). I quickly ran into an error about the base class Panel being nonserializable. So I created my own class that inherits from Panel and implemented the ISerializable interface. At the surface, everything appears to work, at least everything at design time. I don't know what would happen if I tried to run the application.

Anyway, the errors occur when I try to open a file that contains my custom control. For example, I create a new Windows Form and add my custom control to it. I save the Form and close it. Then I try to open the form and get the following error:

Code:
Object of type 'MyTestApplication.SerializablePanel[]' cannot be converted to type 'MyTestApplication.SerializablePanel[]'.
I don't know what I'm doing wrong? I've opened the XML file to see what it's actually writing, and read the header notes about using binary base64 serialization. I think that's what I'm using, but I'm not sure.

Below is the code for the class SerializablePanel

Code:
Imports System.Runtime.Serialization
Imports System.ComponentModel

<Serializable()> _
Public Class SerializablePanel
    Inherits Panel

    Implements ISerializable

#Region "Initializers"
    Public Sub New()
    End Sub
#End Region

#Region "Properties"
    Private _Text As String = Nothing
    <Browsable(True)> _
    Public Overrides Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property
#End Region

#Region "Serialization"
    Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        _Text = info.GetString("Text")
    End Sub

    Public Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) Implements System.Runtime.Serialization.ISerializable.GetObjectData
        info.AddValue("Text", _Text)
    End Sub
#End Region
End Class
Hopefully, my code isn't too bad, I'm just a hobby coder.