R
RSH
Hi,
I have a situation where I am serializing a custom object into an XML string
that is stored on a Session variable.
The problem is I can't seem to figure out how to get it back to an object.
Serialization:
' WORKS FINE
Public Function SerializeObject(ByVal obj As CompanyBase)
Dim oXS As XmlSerializer = New XmlSerializer(obj.GetType)
Dim oStrW As New StringWriter
Dim sXML As String
oXS.Serialize(oStrW, obj)
sXML = oStrW.ToString()
oStrW.Close()
Return sXML
End Function
' GENERATES AN 'ILLEGAL CHARACTERS EXCEPTION
' str is the XML string created by the function above
Public Function DeserializeObject(ByVal str As String) As CompanyBase
Dim oCompanyBase As CompanyBase = New CompanyBase
Dim oXS As XmlSerializer = New XmlSerializer(oCompanyBase.GetType) <-------
Is there a way to not have to instantiate oCompany just to get at the type?
Dim oStmR As StreamReader
oStmR = New StreamReader(str)
oCompanyBase = CType(oXS.Deserialize(oStmR), CompanyBase)
oStmR.Close()
Return oCompanyBase
End Function
Thanks!
Ron
I have a situation where I am serializing a custom object into an XML string
that is stored on a Session variable.
The problem is I can't seem to figure out how to get it back to an object.
Serialization:
' WORKS FINE
Public Function SerializeObject(ByVal obj As CompanyBase)
Dim oXS As XmlSerializer = New XmlSerializer(obj.GetType)
Dim oStrW As New StringWriter
Dim sXML As String
oXS.Serialize(oStrW, obj)
sXML = oStrW.ToString()
oStrW.Close()
Return sXML
End Function
' GENERATES AN 'ILLEGAL CHARACTERS EXCEPTION
' str is the XML string created by the function above
Public Function DeserializeObject(ByVal str As String) As CompanyBase
Dim oCompanyBase As CompanyBase = New CompanyBase
Dim oXS As XmlSerializer = New XmlSerializer(oCompanyBase.GetType) <-------
Is there a way to not have to instantiate oCompany just to get at the type?
Dim oStmR As StreamReader
oStmR = New StreamReader(str)
oCompanyBase = CType(oXS.Deserialize(oStmR), CompanyBase)
oStmR.Close()
Return oCompanyBase
End Function
Thanks!
Ron