title: correct serialize but incorrect Deserialize
body: <p>consider following codes and classes:  </p>
  
  <pre><code>using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Xml.Serialization;
  
  namespace ConsoleApplication1
  {
  
      public class Element1
      {
          [XmlAttribute]
          public int Order { get; set; }
          public string name1 { get; set; }
          public ElementCollcetion collection { get; set; }
      }
  
      public class Element2
      {
          [XmlAttribute]
          public int Order { get; set; }
          public string name2 { get; set; }
      }
  
      public class Elements
      {
          public Element1 element1 { get; set; }
          public Element2 element2 { get; set; }
      }
  
      public interface IFoo
      {
          string FooName { get; set; }
      }
  
      public class Foo1 : IFoo
      {
          public string FooName { get; set; }
          public int deff1 { get; set; }
      }
  
      public class Foo2 : IFoo
      {
          public string FooName { get; set; }
          public bool deff2 { get; set; }
      }
  
      public class ElementCollcetion : List&lt;IFoo&gt;, IXmlSerializable
      {
          public System.Xml.Schema.XmlSchema GetSchema()
          {
              return null;
          }
  
          public void ReadXml(System.Xml.XmlReader reader)
          {
              XmlSerializer serializer = null;
              bool flag;
  
              reader.Read();
              while (true)
              {
                  flag = false;
  
                  if (string.Compare(reader.Name, typeof(Foo1).Name) == 0)
                  {
                      serializer = new XmlSerializer(typeof(Foo1));
                      flag = true;
                  }
                  else if (string.Compare(reader.Name, typeof(Foo2).Name) == 0)
                  {
                      serializer = new XmlSerializer(typeof(Foo2));
                      flag = true;
                  }
  
                  if (flag)
                      this.Add((IFoo)serializer.Deserialize(reader));
                  else
                      break;
              }
          }
  
          public void WriteXml(System.Xml.XmlWriter writer)
          {
              foreach (IFoo foo in this.AsEnumerable())
              {
                  XmlSerializer serializer = new XmlSerializer(foo.GetType());
                  serializer.Serialize(writer, foo);
              }
          }
      }
  
      class Program
      {
          static void Main(string[] args)
          {
              Elements elements = new Elements()
              {
                  element1 = new Element1
                  {
                      name1 = "Name1",
                      Order = 1,
                      collection = new ElementCollcetion(){ 
                          new Foo1{deff1=10,FooName="FooName1"},
                          new Foo2{deff2=true,FooName="FooName2"}
                      },
                  },
  
                  element2 = new Element2
                  {
                      name2 = "Name2",
                      Order = 2
                  }
              };
  
              XmlSerializer serializer = new XmlSerializer(typeof(Elements));
              TextWriter textWriter = new StreamWriter(@"d:\ser.xml");
              serializer.Serialize(textWriter, elements);
              textWriter.Close();
  
              TextReader textReader = new StreamReader(@"d:\ser.xml");
              Elements element = (Elements)serializer.Deserialize(textReader);
              textReader.Close();
          }
      }
  }
  </code></pre>
  
  <p>when i run it, an xml will generated into ser.xml like so:  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Elements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;element1 Order="1"&gt;
      &lt;name1&gt;Name1&lt;/name1&gt;
      &lt;collection&gt;
         &lt;Foo1&gt;
          &lt;FooName&gt;FooName1&lt;/FooName&gt;
          &lt;deff1&gt;10&lt;/deff1&gt;
        &lt;/Foo1&gt;
        &lt;Foo2&gt;
          &lt;FooName&gt;FooName2&lt;/FooName&gt;
          &lt;deff2&gt;true&lt;/deff2&gt;
        &lt;/Foo2&gt;
      &lt;/collection&gt;
    &lt;/element1&gt;
    &lt;element2 Order="2"&gt;
      &lt;name2&gt;Name2&lt;/name2&gt;
    &lt;/element2&gt;
  &lt;/Elements&gt;
  </code></pre>
  
  <p>but it cannot correctly Deserialize the file unless i reorder the elements in the xml like so:  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Elements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;element2 Order="2"&gt;
      &lt;name2&gt;Name2&lt;/name2&gt;
    &lt;/element2&gt;
    &lt;element1 Order="1"&gt;
      &lt;name1&gt;Name1&lt;/name1&gt;
      &lt;collection&gt;
        &lt;Foo1&gt;
          &lt;FooName&gt;FooName1&lt;/FooName&gt;
          &lt;deff1&gt;10&lt;/deff1&gt;
        &lt;/Foo1&gt;
        &lt;Foo2&gt;
          &lt;FooName&gt;FooName2&lt;/FooName&gt;
          &lt;deff2&gt;true&lt;/deff2&gt;
        &lt;/Foo2&gt;
      &lt;/collection&gt;
    &lt;/element1&gt;
  &lt;/Elements&gt;
  </code></pre>
  
  <p>note that <code>serializer.UnknownAttribute</code> and <code>serializer.UnknownElement</code> will not raise during both execution.<br>
  what is the problem? and how can i fix it?  </p>
  
  <p>---------------EDIT----------------------<br>
  i know that problem is in <code>IXmlSerializable.ReadXml()</code> implementation. but what kind of problem and how should i cure it?</p>