title: Serializing a generic collection with XMLSerializer in VB.NET
body: <p>Why won't XMLSerializer process my generic list?</p>
  
  <pre><code>Sub Main()
      Serializing()
  End Sub
  
  &lt;System.Serializable()&gt; _
  Public Class User
      Public Sub New()
      End Sub
  
      Public Sub New(ByVal Username As String, ByVal UserId As Integer)
          Name = Username
          ID = UserId
      End Sub
  
      Public Name As String
      Public ID As Integer
  End Class
  
  Public Sub Serializing()
      Dim Users As New List(Of User)
  
      Dim u As New User
      u.Name = "bob"
      u.ID = 1
      Users.Add(u)
  
      u.Name = "bill"
      u.ID = 2
      Users.Add(u)
  
      u.Name = "ted"
      u.ID = 3
      Users.Add(u)
  
      Dim sw As New System.IO.StringWriter
      Dim ser As New System.Xml.Serialization.XmlSerializer(GetType(List(Of User)))
      ser.Serialize(sw, Users)
  
      Debug.WriteLine(sw.ToString)
  
  End Sub
  </code></pre>
  
  <p>I get an exception on the "Dim ser" line, saying "Testing.Module1 is inaccessible due to its protection level. Only public types can be processed."  ("Testing is the name of the application, and "Module1" is the name of the module; this is a console application).</p>