title: Problem with Serialize/Deserialize objects to/from XML file
body: <p>I have to first deserialize xml file to List then enlarge this list and serialize all with add 1 object more (magnification is needed for this)</p>
  
  <p>code from XML:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
             &lt;name&gt;Danie&lt;/name&gt;
             &lt;lastName&gt;McJackie&lt;/lastName&gt;
             &lt;age&gt;27&lt;/age&gt;
   &lt;/Person&gt;
  </code></pre>
  
  <p>code from .cs file: I commented where i got error and copy the error message</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Xml;
  using System.IO;
  using System.Xml.Serialization;
  
  public partial class _Default : System.Web.UI.Page 
  {
     protected void Page_Load(object sender, EventArgs e)
     {
  
     }
     private List&lt;Person&gt; Deserialize(string path)
     {
         using (FileStream fs = new FileStream(path, FileMode.Open))
         {
             XmlSerializer ser = new XmlSerializer(typeof(List&lt;Person&gt;));
             return (List&lt;Person&gt;)ser.Deserialize(fs);
             //There is an error in XML document (2, 2).
             // I got this error and don't know how to manage with it.
         }
     }
  
     protected void Button1_Click(object sender, EventArgs e)
     {
         string path = Server.MapPath(Request.ApplicationPath + "/test.xml");
         List&lt;Person&gt; people = File.Exists(path) ? Deserialize(path) :new List&lt;Person&gt;();
         people.Add(new Person(TextBox1.Text, TextBox2.Text, int.Parse(TextBox3.Text)));
         using (FileStream fs = File.OpenWrite(path))
         {
             XmlSerializer ser = new XmlSerializer(typeof(List&lt;Person&gt;));
             ser.Serialize(fs, people);
         }
  
  
     }
  }
  </code></pre>
  
  <p>and at least class to serialize:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  
  
  [Serializable]
  public class Person
  {
  
     public string name;
     public string lastName;
     public int age;
     public Person(string _name, string _lastName, int _age)
     {
         name = _name;
         lastName = _lastName;
         age = _age;
     }
     public Person()
     {
  
     }
  }
  </code></pre>
  
  <p>exception details: </p>
  
  <pre><code>System.InvalidOperationException was unhandled by user code
  Message=There is an error in XML document (2, 2).
  Source=System.Xml
  StackTrace:
        at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,                                             String    encodingStyle, XmlDeserializationEvents events)
     at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
     at _Default.Deserialize(String path) in e:\Programy c#\WebSites\ASP8\Default.aspx.cs:line 22
     at _Default.Button1_Click(Object sender, EventArgs e) in e:\Programy c#\WebSites\ASP8\Default.aspx.cs:line 29
     at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
     at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
     at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
     at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
         at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)                
         at System.Web.UI.Page.ProcessRequestMain(Boolean                                                                includeStagesBeforeAsyncPoint,       Boolean includeStagesAfterAsyncPoint)
    InnerException: System.InvalidOperationException
         Message=&lt;Person xmlns=''&gt; was not expected.
     Source=_1r-cm1p
     StackTrace:
          at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1.Read3_ArrayOfPerson()
     InnerException: 
  </code></pre>
  
  <p><strong>This is what i added with last edit</strong></p>
  
  <p>Deserialize file .cs:</p>
  
  <pre><code>string path = Server.MapPath(Request.ApplicationPath + "/test.xml");
      using (FileStream fs = new FileStream(path, FileMode.Open))
      {
          XmlSerializer ser = new XmlSerializer(typeof(List&lt;Person&gt;));
          List&lt;Person&gt; os = (List&lt;Person&gt;)ser.Deserialize(fs);
          foreach (var i in os)
          {
              Label1.Text += i.Name + "&lt;hr /&gt;" + i.LastName + "&lt;hr /&gt;" + i.Age.ToString() + "&lt;hr /&gt;";
          }
  
          fs.Close();
  </code></pre>
  
  <p>everything work fine thanks everyone for help:)</p>