xml and serilisation

  • Thread starter Thread starter spike232
  • Start date Start date
S

spike232

Guest
i have the following code that works for binary serilisation:

Code:
Private Sub binarysave(ByRef hold As Object, ByVal filename As String)
        Dim s As Stream = New FileStream(filename, FileMode.Create)
        Dim b As BinaryFormatter = New BinaryFormatter()

        b.Serialize(s, hold)
        s.Close()
    End Sub

however the folloing to do the same but using xml insted does not work, any ideas??

Code:
    Private Sub xmlsave(ByRef hold As settings, ByVal filename As String)
        Dim s As Stream = New FileStream(filename, FileMode.Create)
       Dim x As XmlSerializer = New XmlSerializer(GetType(settings))

        x.Serialize(s, hold)
        s.Close()
    End Sub
 
i had that originaly it made no difference,


if i change the type pased to XmlSerializer to object it failes on the
x.Serialize(s, hold)

line with error:
An unhandled exception of type System.InvalidOperationException occurred in system.xml.dll

Additional information: There was an error generating the XML document.

insted of the line

Dim x As XmlSerializer = New XmlSerializer(GetType(settings))

with error:
An unhandled exception of type System.InvalidOperationException occurred in system.xml.dll

Additional information: There was an error reflecting MSN_No_Cut_Off.settings.

and the class settings has been declared with <Serializable()>
 
Back
Top