title: Deserialize XML Invalid Operation Exception
body: <p>I am trying to deserialize and xml file using an object that was created with xsd.exe tool. When I tried to run the sample app,  I am getting the following exception, InvalidOperationException - There is an error in XML document (1, 1). What am I doing wrong here?
  Here are my codes:</p>
  
  <p>Sample XML File</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;patient&gt;
   &lt;pr&gt;
  &lt;fname&gt;Cindy &lt;/fname&gt;
  &lt;lname&gt;Knapp &lt;/lname&gt;
  &lt;id&gt;1 &lt;/id&gt;
   &lt;/pr&gt;
   &lt;pr&gt;
  &lt;fname&gt;Regie &lt;/fname&gt;
  &lt;lname&gt;Miller &lt;/lname&gt;
  &lt;id&gt;2 &lt;/id&gt;
   &lt;/pr&gt;
  &lt;ad&gt;
    &lt;id&gt;1&lt;/id&gt;
    &lt;streetnumber&gt;1200 NW&lt;/streetnumber&gt;
    &lt;city&gt;Miami &lt;/city&gt;
    &lt;state&gt;FL&lt;/state&gt;
    &lt;zip&gt;34488&lt;/zip&gt;
  &lt;/ad&gt;
  &lt;ad&gt;
    &lt;id&gt;2&lt;/id&gt;
    &lt;streetnumber&gt;1299 NE&lt;/streetnumber&gt;
    &lt;city&gt;NY &lt;/city&gt;
    &lt;state&gt;NY&lt;/state&gt;
    &lt;zip&gt;9032&lt;/zip&gt;
  &lt;/ad&gt;
  &lt;/patient&gt;
  </code></pre>
  
  <p>Here is the class that was generated</p>
  
  <pre><code>//------------------------------------------------------------------------------
  // &lt;auto-generated&gt;
  //     This code was generated by a tool.
  //     Runtime Version:4.0.30319.18444
  //
  //     Changes to this file may cause incorrect behavior and will be lost if
  //     the code is regenerated.
  // &lt;/auto-generated&gt;
  //------------------------------------------------------------------------------
  
  using System.Xml.Serialization;
  
  // 
  // This source code was auto-generated by xsd, Version=4.0.30319.17929.
  // 
  
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
  [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
  public partial class patient {
  
      private patientPR[] prField;
  
      private patientAD[] adField;
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute("pr")]
      public patientPR[] pr {
          get {
              return this.prField;
          }
          set {
              this.prField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlElementAttribute("ad")]
      public patientAD[] ad {
          get {
              return this.adField;
          }
          set {
              this.adField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
  public partial class patientPR {
  
      private string fnameField;
  
      private string lnameField;
  
      private int idField;
  
      /// &lt;remarks/&gt;
      public string fname {
          get {
              return this.fnameField;
          }
          set {
              this.fnameField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string lname {
          get {
              return this.lnameField;
          }
          set {
              this.lnameField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public int id {
          get {
              return this.idField;
          }
          set {
              this.idField = value;
          }
      }
  }
  
  /// &lt;remarks/&gt;
  [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
  [System.SerializableAttribute()]
  [System.Diagnostics.DebuggerStepThroughAttribute()]
  [System.ComponentModel.DesignerCategoryAttribute("code")]
  [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
  public partial class patientAD {
  
      private int idField;
  
      private string streetnumberField;
  
      private string cityField;
  
      private string stateField;
  
      private ushort zipField;
  
      /// &lt;remarks/&gt;
      public int id {
          get {
              return this.idField;
          }
          set {
              this.idField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string streetnumber {
          get {
              return this.streetnumberField;
          }
          set {
              this.streetnumberField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string city {
          get {
              return this.cityField;
          }
          set {
              this.cityField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public string state {
          get {
              return this.stateField;
          }
          set {
              this.stateField = value;
          }
      }
  
      /// &lt;remarks/&gt;
      public ushort zip {
          get {
              return this.zipField;
          }
          set {
              this.zipField = value;
          }
      }
  }
  </code></pre>
  
  <p>In the main function, I tried to deserialize the xml file.</p>
  
  <pre><code> class Program
      {
          static void Main(string[] args)
          {
              patient pr = new patient();
              XmlSerializer serializer = new XmlSerializer(typeof(patient));
              FileStream myStream = new FileStream(@"C:\com\dss\VXReports\XSD Document\EXAMPLE.CS", FileMode.Open);
              pr = (patient)serializer.Deserialize(myStream);
              string kr = string.Empty;
          }
      }
  
  Stack Trace:
     at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
     at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
     at TestXMLFile.Program.Main(String[] args) in c:\com\dss\VXReports\Clinical Quality Measure\TestXMLFile\TestXMLFile\Program.cs:line 17
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Threading.ThreadHelper.ThreadStart()
  </code></pre>