views:

96

answers:

3

I have this class:

  <Serializable()> _

   Public Class Bonder
    ''' <summary>
    ''' General information
    ''' </summary>
    ''' <remarks></remarks>
    Public BonderName As String
    Public Serial_Number As String
    Public System_Type As String
    Public DM_Version As String
    Public RTS_Build As String
    Public RTS_Label As String
    Public CPU_Boot_Rom As String
    Public BondHead_1 As String = ""
    Public BondHead_2 As String = ""
    Public IP1 As String
    Public IP2 As String
    Public LoadedLeadFrameSetup As String
    Public LoadedMagazineHandler As String
    Public LoadedProcessProgram As String

    ''' <summary>
    ''' Configuration Information
    ''' </summary>
    ''' <remarks></remarks>
    Public ConfigurationKVP As New ArrayList


    ''' <summary>
    ''' Devices on the Bonder
    ''' </summary>
    ''' <remarks></remarks>
    Public DevicesOnBonder As New ArrayList

    ''' <summary>
    ''' RTS server information
    ''' </summary>
    ''' <remarks></remarks>
    Public ServerInfo As New ArrayList


    ''' <summary>
    ''' RTS Options selected
    ''' </summary>
    ''' <remarks></remarks>
    Public Options As New ArrayList

End Class`

This is my code to serialize it and put it into XML format:

  Dim serializer As XmlSerializer
    serializer = New XmlSerializer(currentBonderSetup.GetType)
    Dim tw As New StreamWriter("c:\book1.xml")
    serializer.Serialize(tw, currentBonderSetup)
    tw.Close()

Where am I going wrong? I think the issue is from the ArrayLists but I dont know how to solve it. the ArrayLists contain other objects that to have the Serializeable attribute.

Here are the other classes

<Serializable()> _
Public Class Configs
    Public Item As String
    Public Value As String

    Public Sub New(ByVal key As String, ByVal result As String)
        Item = key
        Value = result
    End Sub

End Class

<Serializable()> _
Public Class BonderDevices
    Public Device_Type As String
    Public Instance As String
    Public Board_Rev As String
    Public Software_Ver As String
    Public Status As String
    Public Data As String

End Class
<Serializable()> _
Public Class ServerInfo
    Public Type As String
    Public Value As String
End Class
+2  A: 

Add a parameterles constructor to Configs ?

   Public Sub New()

   End Sub

Maybe consider giving the serializer a hint about the types, by passing an array of the types into the constructor.

Luhmann
well its choking on Configs and that has a constructor and it is being passed 2 parameters....
Sean P
I don't think the parameterless constructor needs to be public, because it's being used internally.
bryanjonker
i made it public and it worked... i got a different error but im going to include the other classes in the typing.
Sean P
+1  A: 

You may want to check this out:

http://stackoverflow.com/questions/267724/why-serializable-class-need-a-parameterless-constructor

bryanjonker
I get this error now: "The type BMS.Classes+Configs was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
Sean P
+1  A: 

try constructing your serializer so...

var s = new XmlSerializer(typeof(Bonder), new Type[]{typeof(Configs),typeof(BonderDevices),typeof(ServerInfo)});

and, yeah, you need default parameterless constructors on all your types.

in VB

Dim s = New XmlSerializer(GetType(Bonder), New Type() {GetType(Configs), GetType(BonderDevices), GetType(ServerInfo)})
Sky Sanders
Can you give me more info about parameterless constructors???
Sean P
Nevermind...stupid question.
Sean P
I get this error now:"The type BMS.Classes+Configs was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
Sean P
did you try what i suggested?
Sky Sanders
How do I do that in VB.
Sean P
http://converter.telerik.com/ - it isnt perfect but you can usually suss it out. I haven't written any vb professionally for a few years, a bit rusty.
Sky Sanders
Works THANKS A BUNCH!!! Rep'd
Sean P