title: Deserializing List<int> with XmlSerializer Causing Extra Items
body: <p>I'm noticing an odd behavior with the XmlSerializer and generic lists (specifically <code>List&lt;int&gt;</code>). I was wondering if anyone has seen this before or knows what's going on. It appears as though the serialization works fine but the deserialization wants to add extra items to the list. The code below demonstrates the problem.</p>
  
  <p>Serializable class:</p>
  
  <pre><code>public class ListTest
  {
      public int[] Array { get; set; }
      public List&lt;int&gt; List { get; set; }
  
      public ListTest()
      {
          Array = new[] {1, 2, 3, 4};
          List = new List&lt;int&gt;(Array);
      }
  }
  </code></pre>
  
  <p>Test code:</p>
  
  <pre><code>ListTest listTest = new ListTest();
  Debug.WriteLine("Initial Array: {0}", (object)String.Join(", ", listTest.Array));
  Debug.WriteLine("Initial List: {0}", (object)String.Join(", ", listTest.List));
  
  XmlSerializer serializer = new XmlSerializer(typeof(ListTest));
  StringBuilder xml = new StringBuilder();
  using(TextWriter writer = new StringWriter(xml))
  {
      serializer.Serialize(writer, listTest);
  }
  
  Debug.WriteLine("XML: {0}", (object)xml.ToString());
  
  using(TextReader reader = new StringReader(xml.ToString()))
  {
      listTest = (ListTest) serializer.Deserialize(reader);
  }
  
  Debug.WriteLine("Deserialized Array: {0}", (object)String.Join(", ", listTest.Array));
  Debug.WriteLine("Deserialized List: {0}", (object)String.Join(", ", listTest.List));
  </code></pre>
  
  <p>Debug output:</p>
  
  <pre><code>Initial Array: 1, 2, 3, 4
  Initial List: 1, 2, 3, 4
  </code></pre>
  
  <p>XML: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;ListTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Array&gt;
      &lt;int&gt;1&lt;/int&gt;
      &lt;int&gt;2&lt;/int&gt;
      &lt;int&gt;3&lt;/int&gt;
      &lt;int&gt;4&lt;/int&gt;
    &lt;/Array&gt;
    &lt;List&gt;
      &lt;int&gt;1&lt;/int&gt;
      &lt;int&gt;2&lt;/int&gt;
      &lt;int&gt;3&lt;/int&gt;
      &lt;int&gt;4&lt;/int&gt;
    &lt;/List&gt;
  &lt;/ListTest&gt;
  </code></pre>
  
  
  
  <pre><code>Deserialized Array: 1, 2, 3, 4
  Deserialized List: 1, 2, 3, 4, 1, 2, 3, 4
  </code></pre>
  
  <p>Notice that both the array and list appear to have serialized to XML correctly but on deserialization the array comes out correct but the list comes back with a duplicate set of items. Any ideas?</p>