I have an object that I want to serialize to a string variable. I
want to use the SoapFormatter, for readability.
The serialization is working great and I'm pleased with the results.
DeSerialization, however, is giving me an error that "The root element
is missing." This happens even when I pass the return value from
Serialize() directly back to the Deserialize() method.
============ Code Snippet ===============
'Seems to work great.
Public Function Serialize() As String
Dim ms As New MemoryStream
Dim sf As New SoapFormatter
Dim ui As New System.Text.ASCIIEncoding
Dim sw As New StringWriter
sf.Serialize(ms, Me)
sw.Write(ui.GetChars(ms.GetBuffer))
Return sw.ToString
End Function
'Fails with the exception: "The root element is missing."
Public Shared Function Deserialize(ByVal SerializedString As
String) As People
Dim lcDeserialize As People
Try
Dim ms As New MemoryStream
Dim sf As New SoapFormatter
Dim sr As New StreamWriter(ms, System.Text.Encoding.ASCII)
sr.Write(SerializedString)
lcDeserialize = CType(sf.Deserialize(ms), People)
Catch ex As Exception
lcDeserialize = New People
End Try
Return lcDeserialize
End Function
=======================================
I have looked on many sites and in MSDN and there are thousands of
examples of persisting an object Serialization to a file and
Deserializing from there, but I could find no examples of using a
String variable holding the Soap XML.
Thanks.
-Jason
-Kevin Buchan
ke**********@REMOVETHISTOEMAILtroutmansanders.com