Serializing Derived Classes in VB.NET

Glenn Dekerlegand

New member
Joined
Oct 26, 2006
Messages
1
Programming Experience
Beginner
:confused: I have a project I am developing and am having trouble serializing my derived objects. I will try to describe the problem along with some of the code. I am new to programming so I hope to make sense enough for a resolution. Thanks in advanceJ

Classes:
Task.vb
TaskCollection.vb (Inherits CollectionBase)
TaskLogic.vb
TaskNotifier.vb (Base Class)
TaskNotifierCollection.vb (Inherits CollectionBase)

Each Task instantiated has one logic class but can have several notifiers
Several classes that derive from TaskNotifier as example are TaskNotifier_Email, TaskNotifier _SMSMessage, TaskNotifier _LogFile, TaskNotifier _Pager ect. They all share TaskNotifier’s methods but have unique properties as needed to notify. When I try to serialize the Task Collection the method fails. My derived classes all have different properties, but running Notify makes it happen. During XML Serialazation I don’t think the different types are recongnized and can seem to get anything to work. I have tried different xmlattributes ect.

<System.Serializable()> Public Class Task
Private _notifiers As New TaskNotifierCollection
Public Sub New()
End sub
End Class

<System.Serializable()> Public Class TaskLogic
Public Sub New()
End Sub
Public Sub Logic()
End Sub
End Class

Public MustInherit Class TaskNotifier
Protected MustOverride Function HasActiveSchedule() As Boolean
Protected MustOverride Sub Notify()
End Class

Public Sub SerializeData()
Try
Dim writer As New XmlSerializer(GetType(Task.TaskCollection))
Dim file As New StreamWriter("SerializedTasks.xml")
writer.Serialize(file, myTasks)
file.Close()
End Try
End Sub
 
Back
Top