title: How to serialize a class with a list of custom objects?
body: <p>I have two classes:</p>
  
  <pre><code>namespace Something
  {
      [Serializable]
      public class Spec
      {
          public string Name { get; set; }
  
          [XmlArray]
          public List&lt;Value&gt; Values { get; set; }
      }
  
      [Serializable]
      public class Value
      {
          public string Name { get; set; }
  
          public short StartPosition { get; set; }
  
          public short EndPosition { get; set; }
  
          public Value(string name, short startPosition, short endPosition)
          {
              Name = name;
              StartPosition = startPosition;
              EndPosition = endPosition;
          }
      }
  }
  </code></pre>
  
  <p>When I try to serialize</p>
  
  <pre><code>var spec = new Spec();
  spec.Name = "test";
  spec.Values = new List&lt;Value&gt; { new Value("testing", 0, 2) };
  
  var xmls = new XmlSerializer(spec.GetType());    
  xmls.Serialize(Console.Out, spec);
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p><strong>InvalidOperationException</strong></p>
    
    <p>There was an error reflecting type 'Something.Spec'</p>
  </blockquote>
  
  <p>Using a list of <code>string</code> I don't have any problems. Am I missing some attribute?</p>