title: Serialize an object that contains a list of objects
body: <p>I'v build a NotInheritable Serilizer that serilizes all my classes and list of classes with success.
  Until I'v build a list of class that contains a list of classes.
  I'm getting the runtime Exeption: There was an error generating the XML document. resulting in a perfectly empty XML :(</p>
  
  <p>These are my classes to serilize:</p>
  
  <pre><code>&lt;System.Serializable&gt; _
  &lt;System.Xml.Serialization.XmlInclude(GetType(StatisticItem))&gt; _
  Public Class Statistic
      Public StatItem As New list(Of StatisticItem)
      'Bla bla bla
  end class
  
  
  &lt;Serializable&gt; _
  Public Class StatisticItem              
          Private stStatPath As String = ""    
          Private eStatType As StatType = 0
          Private iBatchNumber As Int32 = 0
  end class
  </code></pre>
  
  <p>And the serializer:</p>
  
  <pre><code>Public NotInheritable Class XmlSerializer       
  
      Public Shared Sub Serialize(Of T)(ByVal obj As T, sConfigFilePath As String)        
          Dim XmlBuddy As New System.Xml.Serialization.XmlSerializer(GetType(T))
          Dim MySettings As New System.Xml.XmlWriterSettings()
          MySettings.Indent = True
          MySettings.CloseOutput = True       
          Dim MyWriter As System.Xml.XmlWriter=System.Xml.XmlWriter.Create(sConfigFilePath,MySettings)        
          XmlBuddy.Serialize(MyWriter,obj) 
          MyWriter.Flush()
          MyWriter.Close()    
  
          ' ----- OLD CODE FOR SERIALIZE, NEXTLINE IN XML DOESNT WORK ON WIN CE -------, 
          ' B.T.W. Using This code to serilize gives the exact same fault             
          'Dim XmlBuddy As New System.Xml.Serialization.XmlSerializer(GetType(T))
          'Dim objStreamWriter As New StreamWriter(sConfigFilePath)
          'XmlBuddy.Serialize(objStreamWriter, obj)
          'objStreamWriter.Close()
      End Sub
   end class
  </code></pre>
  
  <p>And this is the call:</p>
  
  <pre><code> XmlSerializer.Serialize(Of list(Of Statistic))(StatCollection, CommCtrl.PathStatisticFile)
  </code></pre>
  
  <p>If i comment the list in StatisticItem everything works.</p>
  
  <p>I think if I Implement IXmlSerializable in StatisticItem I can tell the serializer how to work to make it work, but I see other code example on the internet where this works without all this effort
  and I prefer a clean solution, that is about the same as all my other classes.</p>
  
  <p>Hope one of you guys can help me out                </p>