title: XmlSerializer Deserializing Array/List of Multiple Objects at Root
body: <p>I'm trying to deserialize the following XML output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;Foo&gt;
     &lt;Val&gt;Data1&lt;/Val&gt;
  &lt;/Foo&gt;
  &lt;Foo&gt;
     &lt;Val&gt;Data2&lt;/Val&gt;
  &lt;/Foo&gt;
  </code></pre>
  
  <p>(This is output from a hardware device, and cannot be changed)</p>
  
  <p>I have an XML type defined as:</p>
  
  <pre><code>    [XmlType(AnonymousType=true, Namespace="")]
      public class Foo
      {
          public string Val { get; set; }
      }
  </code></pre>
  
  <p>I've tried to deserialize this array by creating a serializer like:</p>
  
  <pre><code>  var s = new XmlSerializer(typeof(Foo[]));
    //or
    var s = new XmlSerializer(typeof(List&lt;Foo&gt;);
  </code></pre>
  
  <p>But every call to s.Deserialize() causes an InvalidOperaitonException:</p>
  
  <pre><code> System.InvalidOperationException: &lt;Foo xmlns=''&gt; was not expected.
  </code></pre>
  
  <hr>
  
  <p><strong>Note</strong></p>
  
  <pre><code> var s = new XmlSerializer(typeof(Foo));
   // Only deseralizes the first Foo (Data1).
  </code></pre>
  
  <p>Thanks for your help.</p>