title: Serializing when class inherits list (of object)
body: <p>I have a BOOKING class that inherits a list (of Message)
  I was wondering how to serialize this. 
  my BOOKING class contains the property of Message and 3 attributes called partner, transaction and version,</p>
  
  <p>My Message class has numerous properties to create a booking,</p>
  
  <p>now when I want to serialize I use this</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Dim z As New BOOKING
  Dim x As New Message
  z.partner = "company name"
  z.transaction = "BOOKING"
  z.version = "1.0"
  x.MessageType = "C"
  x.CustomerNumber = "123"
  x.BookingReference = "5845"
  x.CustomerBookingReference = "036598"
  x.OutwardRoute = "PEMROS"
  x.SailingDate = "20120107"
  z.Message = x
  SaveAsXML(z)
  </code></pre>
  
  <p>with the save as xmlfunction code below</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Shared Function SaveAsXML(ByRef val As BOOKING)
      Try
  
          Dim objStreamWriter As New StreamWriter("c:\ftptest\New Booking\" + val.FileName)
          Dim y As New XmlSerializer(val.GetType)
          y.Serialize(objStreamWriter, val)
          objStreamWriter.Close()
  
          Return True
      Catch ex As Exception
          Throw ex
      End Try
  End Function
  </code></pre>
  
  <p>any idea where I'm going wrong?</p>
  
  <p>my BOOKING class is as follows</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Class BOOKING : Inherits List(Of Message)
  
  
  Private Property MessageProperty As Message
  
  &lt;XmlAttribute&gt;
  Public Property partner As String
  &lt;XmlAttribute&gt;
  Public Property transaction As String
  &lt;XmlAttribute&gt;
  Public Property version As String
  
  
  Public Property Message As Message
      Get
          Return MessageProperty
      End Get
      Set(value As Message)
          MessageProperty = value
      End Set
  End Property
  </code></pre>
  
  <p>Also here is the xml created by the above code.</p>
  
  <pre class="lang-vb prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ArrayOfMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt;
  </code></pre>
  
  <p>Here is my deserializing code</p>
  
  <pre class="lang-vb prettyprint-override"><code> Try
          Dim Samples As BOOKING
          Using objStreamReader As New StreamReader(filepath) 'Path where file is
              Dim x As New XmlSerializer(GetType(BOOKING), New XmlRootAttribute("BOOKING"))
              Samples = x.Deserialize(objStreamReader)
          End Using
          Form1.DataGridView1.DataSource = Samples
          Return True
      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try
  </code></pre>