title: Deserializing XML to objects which has list of objects in C#
body: <p>I have following xml which I want to Deserialize to an object.</p>
  
  <pre><code>&lt;result&gt;
      &lt;reporttype&gt;2&lt;/reporttype&gt;
      &lt;items&gt;
          &lt;item&gt;
              &lt;sku&gt;0B0005&lt;/sku&gt;
              &lt;style&gt;0B0005.DAK.GREY&lt;/style&gt;
              &lt;reason&gt;Barcode cannot be moved to different SKUs&lt;/reason&gt;
          &lt;/item&gt;
          &lt;item&gt;
              &lt;sku&gt;0B0006&lt;/sku&gt;
              &lt;style&gt;0B0006.DAK.GREY&lt;/style&gt;
              &lt;reason&gt;Barcode cannot be moved to different SKUs&lt;/reason&gt;
          &lt;/item&gt;
      &lt;/items&gt;
  &lt;/result&gt;
  </code></pre>
  
  <p>But following code does not populate the item list, Can someone point me out what I am doing wrong here</p>
  
  <pre><code>string inputString = @"&lt;result&gt;&lt;reporttype&gt;2&lt;/reporttype&gt;&lt;items&gt;&lt;item&gt;&lt;sku&gt;0B0005&lt;/sku&gt;&lt;style&gt;0B0005.DAK.GREY&lt;/style&gt;&lt;reason&gt;Barcode cannot be moved to different SKUs&lt;/reason&gt;&lt;/item&gt;&lt;item&gt;&lt;sku&gt;0B0005&lt;/sku&gt;&lt;style&gt;0B0005.DAK.GREY&lt;/style&gt;&lt;reason&gt;Barcode cannot be moved to different SKUs&lt;/reason&gt;&lt;/item&gt;&lt;/items&gt;&lt;/result&gt;";
  
  XmlDocument doc = new XmlDocument();
  doc.LoadXml(inputString);
  
  XmlSerializer serializer = new XmlSerializer(typeof(Result));
  StringReader rdr = new StringReader(doc.InnerXml);
  Result resultingMessage = (Result)serializer.Deserialize(rdr);
  
  public enum ReportType {
      [XmlEnum("0")]
      InternalErrorReport,
      [XmlEnum("1")]
      ErrorReport,
      [XmlEnum("2")]
      InternalSuccessReport
  }
  
  [XmlRoot(ElementName = "result")]
  public class Result {
      [XmlElement(ElementName = "reporttype")]
      public ReportType reportType { get; set; }
      [XmlElement(ElementName = "items")]
      public List&lt;Item&gt; items = new List&lt;Item&gt;();
  
      public string error { get; set; }
  
      public class Item {
          [XmlElement(ElementName = "sku")]
          string sku { get; set; }
          [XmlElement(ElementName = "style")]
          string style { get; set; }
          [XmlElement(ElementName = "reason")]
          string reason { get; set; }
      }
  }
  </code></pre>
  
  <p>Or is there a better way to do this?</p>