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 ArrayLi开发者_如何转开发st
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
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.
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)})
精彩评论