title: How to Deserialize xml to an array of objects?
body: <p>I am tryind to deserialize a xml file into an object[] - the object is a rectangle with the following fields</p>
  
  <pre><code>public class Rectangle : IXmlSerializable
  {
      public string Id { get; set; }
      public Point TopLeft { get; set; }
      public Point BottomRight { get; set; }
      public RgbColor Color { get; set; }
  }
  </code></pre>
  
  <p>I created several rectangles, saved them into an array and managed to serialize them into the xml i get the following syntax:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; 
  - &lt;Rectangles&gt;
   - &lt;Rectangle&gt;
      &lt;ID&gt;First one&lt;/ID&gt; 
    - &lt;TopLeft&gt;
      &lt;X&gt;0.06&lt;/X&gt; 
      &lt;Y&gt;0.4&lt;/Y&gt; 
      &lt;/TopLeft&gt;
    - &lt;BottomRight&gt;
      &lt;X&gt;0.12&lt;/X&gt; 
      &lt;Y&gt;0.13&lt;/Y&gt; 
      &lt;/BottomRight&gt;
    - &lt;RGB_Color&gt;
      &lt;Blue&gt;5&lt;/Blue&gt; 
      &lt;Red&gt;205&lt;/Red&gt; 
      &lt;Green&gt;60&lt;/Green&gt; 
      &lt;/RGB_Color&gt;
    &lt;/Rectangle&gt;
  </code></pre>
  
  <p>- </p>
  
  <p>Now i want to deserialize the rectangle objects back into a new rectangle[]
  how should i do it?</p>
  
  <pre><code>XmlSerializer mySerializer = new XmlSerializer(typeof(Rectangle));
          FileStream myFileStream = new FileStream("rectangle.xml", FileMode.Open);
          Rectangle[] r = new Rectangle[] {};
          Rectangle rec;
          for (int i = 0; i &lt; 3; i++)
          {
              r[i] = (Rectangle) mySerializer.Deserialize(myFileStream);
          }
  </code></pre>
  
  <p>i get a InvalidOperationException - {"There is an error in XML document (1, 40)."}
  what am i doing wrong?</p>
  
  <p>Thank you </p>