When I run the following code I get a message that the Parent class is not marked as serializable. This is very annoying since Im not trying to serialize the Parent. Is this is a bug in Visual Studio? How do I get around it?
Code:
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FileStream As Stream = File.Create("C:\abc.abc")
Dim serializer As New BinaryFormatter
With serializer
Dim Child1 As New Child
Dim Parent1 As Parent = New Parent(Child1)
.Serialize(FileStream, Child1) Get an error at this line - "Parent... is not marked as Serializable."
End With
End Sub
End Class
Public Class Parent
Inherits PictureBox this is why I cant serialise the Parent class
Friend WithEvents MyChild As Child
Friend Sub New(ByVal newChild As Child)
MyChild = newChild
newChild.MyParent = Me
End Sub
Private Sub ChildNotify() Handles MyChild.InformParent
End Sub
End Class
<Serializable()> Public Class Child
Event InformParent()
<NonSerialized()> Friend MyParent As Parent
End Class