title: C# SOAP client unable to deserialize response ("There is an error in XML document")
body: <p>I added a reference to a Web Service in my project. I'm using the generated code to call the methods of the Web Service. One of the methods returns the following structure:</p>
  
  <pre><code>    &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:typens="urn:AllegroWebApi" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"&gt;
         &lt;SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
            &lt;typens:doGetCatsDataResponse&gt;
               &lt;cats-list xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="typens:CatInfoType[24051]"&gt;
                  &lt;item xsi:type="typens:CatInfoType"&gt;
                     &lt;cat-id xsi:type="xsd:int"&gt;26013&lt;/cat-id&gt;
                     &lt;cat-name xsi:type="xsd:string"&gt;Antyki i Sztuka&lt;/cat-name&gt;
                     &lt;cat-parent xsi:type="xsd:int"&gt;0&lt;/cat-parent&gt;
                     &lt;cat-position xsi:type="xsd:int"&gt;0&lt;/cat-position&gt;
                     &lt;cat-is-product-catalogue-enabled xsi:type="xsd:int"&gt;0&lt;/cat-is-product-catalogue-enabled&gt;
                  &lt;/item&gt;
              ....
  
              &lt;/item&gt;
              &lt;item xsi:type="typens:CatInfoType"&gt;
                 &lt;cat-id xsi:type="xsd:int"&gt;124895&lt;/cat-id&gt;
                 &lt;cat-name xsi:type="xsd:string"&gt;Pozostałe&lt;/cat-name&gt;
                 &lt;cat-parent xsi:type="xsd:int"&gt;124883&lt;/cat-parent&gt;
                 &lt;cat-position xsi:type="xsd:int"&gt;5&lt;/cat-position&gt;
                 &lt;cat-is-product-catalogue-enabled xsi:type="xsd:int"&gt;0&lt;/cat-is-product-catalogue-enabled&gt;
              &lt;/item&gt;
              &lt;item xsi:type="typens:CatInfoType"&gt;
                 &lt;cat-id xsi:type="xsd:int"&gt;124894&lt;/cat-id&gt;
                 &lt;cat-name xsi:type="xsd:string"&gt;Teleskopy&lt;/cat-name&gt;
                 &lt;cat-parent xsi:type="xsd:int"&gt;124883&lt;/cat-parent&gt;
                 &lt;cat-position xsi:type="xsd:int"&gt;6&lt;/cat-position&gt;
                 &lt;cat-is-product-catalogue-enabled xsi:type="xsd:int"&gt;0&lt;/cat-is-product-catalogue-enabled&gt;
              &lt;/item&gt;     // Line 168361   &lt;--------------- HERE
           &lt;/cats-list&gt;
           &lt;ver-key xsi:type="xsd:long"&gt;91632766&lt;/ver-key&gt;
           &lt;ver-str xsi:type="xsd:string"&gt;1.1.47&lt;/ver-str&gt;
        &lt;/typens:doGetCatsDataResponse&gt;
     &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>The generated code that is responsible for deserializing it throws the following exception:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.InvalidOperationException'
    occurred in System.Xml.dll Additional information: There is an error
    in XML document (168361, 13).</p>
  </blockquote>
  
  <p>I marked the line that is mentioned in the exception in the code sample. I guess it has something to do with the fact that it is the closing tag of the last <code>item</code> object. I have no idea why it is failing. The XML is well formated and does not seem to include any unsupported characters.</p>