Getting the following error from this code:
"System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type xml_parser.Module1+Stats was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
Code:Imports System.IO Imports System.Xml Public Module Module1 Sub Main() Dim host As New Stats host.Name = "test1" host.FQDN = "test1.lab.local" host.IP = "192.168.5.6" host.UserID = "user1" Console.WriteLine(ToXML(host)) Console.ReadKey() End Sub 'Convert Host data table to XML format for saving to file: Public Function ToXML(ByVal obj As Object) As String Try Dim x As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(GetType(Object)) Dim sw As New StringWriter() x.Serialize(sw, obj) Return sw.ToString Catch ex As Exception Console.WriteLine(ex.ToString) Console.ReadKey() End Try End Function Public Function ToStruct(ByVal xString As String, ByVal type As Type) As Object Dim x As New Xml.Serialization.XmlSerializer(type) Dim sw As New IO.StringReader(xString) Return x.Deserialize(sw) End Function ' Host data table details: <Serializable()> Public Structure Stats Dim Name As String Dim FQDN As String Dim IP As String Dim UserID As String End Structure End Module




Reply With Quote
