Your class structure is confusing the serializer. If Booking
inherits from List(Of Message) then it makes little sense for it to also have a Message
Property Of Type Message
(because it is already a message type). It becomes a self reference. There are a few other issues and tweaks I made and it serialized fine:
Public Class BOOKING
Public Property partner As String
Public Property transaction As String
Public Property version As String
Public Property XMsgs As New List(Of XMessage)
End Class
Public Class XMessage
Public Property A As String
Public Property C As String
Public Property B As String
End Class
a) Public Property Message As Message
it is ill advised in VB to give a the property the same name as the type. Hence I used XMessage
b) you where not using XMLAttribute correctly. There should have been several IDE errors and it is not needed for XML serialization
c) To handle more than one Message per packet, I changed XMsgs to a List property. This allows one BOOKING dataset for many messages. If you want 1 Msg Per Booking there is no need for 2 classes and just make it a List(Of Booking).
d) got rid of the private property used as a backing field.
Test and serialization code:
Dim B As New BOOKING
B.partner = "abcdef"
B.transaction = "12345"
B.version = "1.00.1"
Dim m As New XMessage
m.A = "foo"
m.B = "bar"
B.XMsgs.Add(m) ' use List prop as a List
' Using block to dispose of streamwriter
Using sr As New System.IO.StreamWriter("c:\Temp\Booking.xml")
Dim y As New Serialization.XmlSerializer(B.GetType)
y.Serialize(sr, B)
End Using