C
cowznofsky
I have been using the below to serialize and deserialize my Foo class.
But I haven't been able
to inherit from Foo class (let's call it FooChild) and get it to work.
sXML is the result of the serialization. I want to instantiate a new
FooChild from DeserializeXML below, but when I try
I get an error saying it couldn't cast to FooChild. This also fails if
I try a DirectCast.
Public Function SerializeToXML() As String
Try
Dim o As New Foo
Dim serializer As XmlSerializer = New
XmlSerializer(GetType(Foo))
Dim sw As StringWriter = New StringWriter
serializer.Serialize(sw, o)
Return sw.ToString
Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Function
Public Shared Function DeserializeXML(ByVal sXML As String) As Foo
Dim serializer As XmlSerializer = New
XmlSerializer(GetType(Foo))
Dim sr As StringReader = New StringReader(sXML)
Return CType(serializer.Deserialize(sr), Foo)
End Function
But I haven't been able
to inherit from Foo class (let's call it FooChild) and get it to work.
sXML is the result of the serialization. I want to instantiate a new
FooChild from DeserializeXML below, but when I try
I get an error saying it couldn't cast to FooChild. This also fails if
I try a DirectCast.
Public Function SerializeToXML() As String
Try
Dim o As New Foo
Dim serializer As XmlSerializer = New
XmlSerializer(GetType(Foo))
Dim sw As StringWriter = New StringWriter
serializer.Serialize(sw, o)
Return sw.ToString
Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Function
Public Shared Function DeserializeXML(ByVal sXML As String) As Foo
Dim serializer As XmlSerializer = New
XmlSerializer(GetType(Foo))
Dim sr As StringReader = New StringReader(sXML)
Return CType(serializer.Deserialize(sr), Foo)
End Function