title: There is an error in XML document; EndElement is an invalid XmlNodeType when deserializing
body: <p>Consider a .NET client calling into a remote XML SOAP web service that's defined as a Web Reference. The client calls the service, and is attempting to deserialize the return XML into an object.</p>
  
  <p>The web method is executing properly, and the XML returned from the service is well formed, confirmed in Fiddler. The web service is a known good working service, as we have another client (.NET 2.0) consuming it without issue. </p>
  
  <p>When the .NET web service proxy classes attempt to deserialize the returned XML, this error is thrown:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: There is an error in XML document (1, 1999). ---> 
    System.Xml.XmlException: 'EndElement' is an invalid XmlNodeType. Line 1, position 1999.   at System.Xml.XmlReader.ReadStartElement()<br>
    at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader_PRPA_AR101202_Service.Read135_MCCI_MT000200LocatedEntity(Boolean isNullable, Boolean checkType)   </p>
  </blockquote>
  
  <p>The line/column (1,1999) of the <a href="https://gist.github.com/philoushka/485989cffc83b2fbcb51/raw/7a92873b3509c52692aeb64a8539eabf74e644dd/gistfile1.xml" rel="nofollow">XML response</a> that it's complaining about is the <code>/</code> in <code>&lt;/device&gt;</code>:</p>
  
  <pre><code>&lt;sender&gt;
     &lt;device&gt;
        ..snip..
        &lt;location classCode="IDENT" realmCode="xyz" /&gt;
     &lt;/device&gt;
  </code></pre>
  
  <p><strong>How can I resolve this issue with .NET deserialization?</strong></p>
  
  <p>Attempted solutions with no resolution / more information:</p>
  
  <ul>
  <li>moved from .NET 4 to 4.5, hoping to see any fixes in the newest <code>System.Xml</code></li>
  <li><a href="https://gist.github.com/philoushka/485989cffc83b2fbcb51/raw/7a92873b3509c52692aeb64a8539eabf74e644dd/gistfile1.xml" rel="nofollow">de-identified response document being deserialized</a></li>
  <li><a href="https://gist.github.com/philoushka/4724f30b4ae7c3f1548a/raw/76fde52fa4ee3c2b52b3df03675c96b4abcd59e8/gistfile1.txt" rel="nofollow">full stack trace</a></li>
  </ul>