title: Deserialization of XML list objects in C#
body: <p>I am trying to deserialize an xml in c# which looks like this (shortened version):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;map&gt;
      &lt;parts&gt;
        &lt;part name="default part"&gt;
          &lt;objects count="1597"&gt;
              &lt;object type="1" symbol="6"&gt;
                  &lt;coords count="130"&gt;
                      &lt;coord x="-221595" y="-109687" flags="1"/&gt;
                      &lt;coord x="-221625" y="-109744"/&gt;
                      &lt;coord x="-221640" y="-109785"/&gt;
                      &lt;coord x="-221640" y="-109841" flags="1"/&gt;
                      &lt;coord x="-221655" y="-109969"/&gt;
                      &lt;coord x="-221655" y="-110040"/&gt;
                      &lt;coord x="-221640" y="-110164" flags="1"/&gt;
                      &lt;coord x="-221640" y="-110209"/&gt;
                      &lt;coord x="-221655" y="-110265"/&gt;
                  &lt;/coords&gt;
                  &lt;pattern rotation="0"&gt;
                      &lt;coord x="0" y="0"/&gt;
                  &lt;/pattern&gt;
              &lt;/object&gt;
            &lt;/objects&gt;
          &lt;/part&gt;
     &lt;/parts&gt;
  &lt;/map&gt;
  </code></pre>
  
  <p>Using the classes below:</p>
  
  <pre><code>[XmlRoot("map")] 
  public class Map {
  
  
      [XmlElement(ElementName = "parts")]
      public List&lt;Part&gt; parts { get; set; }
  
      public Map()
      {
           parts = new List&lt;Part&gt;();
      }
  
  
  public class Part {
  
      [XmlElement(ElementName = "objects")]
      public List&lt;KdToPostGISProject.Object&gt; objects { get; set; }
  
      public Part()
      {
          objects = new List&lt;KdToPostGISProject.Object&gt;();
      }
  
      [XmlAttribute(AttributeName = "name")]
      public String name { get; set; }     
  
  }
  
  public class Object
      {
           [XmlElement(ElementName = "coords")]
           public List&lt;Coord&gt; coords { get; set; } 
  
            public Object()
            {
               coords = new List&lt;Coord&gt;();
            }
      }
  
  
  public class Coord
  {
      [XmlAttribute]
      public int x { get; set; }
      [XmlAttribute]
      public int y { get; set; }
  }
  </code></pre>
  
  <p>And the main function:</p>
  
  <pre><code>var serializer = new XmlSerializer(typeof(Map), new XmlRootAttribute("map"));               
  
  Map resultingMessage = (Map)serializer.Deserialize(new FileStream(@"myXml.xml", FileMode.Open));
  </code></pre>
  
  <p>For some reason which I've been trying to figure out I keep getting zero objects (and null name) in my part-class. Right now I'm stuck, anyone who has any input?</p>