title: There is an error in XML Document (0,0)
body: <p>I have spent countless hours working on this issue, and have tried so many different things. Some background... I am working within an SSIS module using C# code to attempt to deserialize a SOAP XML stream. I have been able to deserialize XML streams before, but this one is significantly more complicated than the previous ones I have been involved with.</p>
  
  <p>I have verified that the string I am using to populate my stream is correct for the results, and I am reaching the end of my rope. </p>
  
  <p>Here is the method I am using to try to deserialize. You can see I have included several commented out sections to show some of the other methods I have used to try to make this work:</p>
  
  <pre><code>private Envelope GetWebServiceResultFromStream(StreamReader str)
  {
  
      bool b = true;
      Envelope xmlResponse = null;
      String xmlPayload = "";
  
     //Deserialize our XML
      try
      {
          //System.Runtime.Serialization.Formatters.Soap.SoapFormatter soapFormatter = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
  
          //using (Stream savestream = str.BaseStream)
          //{
          //    xmlResponse = (Envelope)soapFormatter.Deserialize(savestream);
          //}
  
  
          System.Xml.Serialization.XmlSerializer sr = new System.Xml.Serialization.XmlSerializer(typeof(Envelope));
  
          using (Stream savestream = str.BaseStream)
          {
              StreamReader streamreader = new StreamReader(savestream, Encoding.UTF8);
              xmlPayload = streamreader.ReadToEnd();
  
              //xmlPayload = System.Security.SecurityElement.Escape(xmlPayload);
  
              //xmlPayload = xmlPayload.Replace("&amp;amp;", "&amp;");
              //xmlPayload = xmlPayload.Replace("&amp;", "&amp;amp;");
              xmlPayload = xmlPayload.Replace("'", "&amp;apos;");
              //xmlPayload = xmlPayload.Replace("soap:Envelope", "Envelope");
  
  
              File.WriteAllText(@"myxml.xml",xmlPayload);
  
  
  
              byte[] byteArray = Encoding.UTF8.GetBytes(xmlPayload);
              MemoryStream secondstream = new MemoryStream(byteArray);
              secondstream.Position = 0;
  
              xmlResponse = sr.Deserialize(secondstream) as Envelope;
  
              //xmlResponse = (Envelope)DeserializeFromXml&lt;Envelope&gt;(xmlPayload);
  
              //XmlDocument doc = new XmlDocument();
              //doc.Load(secondstream);
              //XmlNodeReader reader = new XmlNodeReader(doc);
              //using (reader)
              //{
              //    xmlResponse = sr.Deserialize(reader) as Envelope;
              //}
  
  
              //System.Runtime.Serialization.Formatters.Soap.SoapFormatter soapFormatter = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
  
  
              //xmlResponse = (Envelope)soapFormatter.Deserialize(secondstream);
  
  
          }
  
          //XmlDocument xmlSoapRequest = new XmlDocument();
          //using (Stream savestream = str.BaseStream)
          //{
          //    using (StreamReader readStream = new StreamReader(savestream, Encoding.UTF8))
          //    {
          //        xmlSoapRequest.Load(readStream);
          //        xmlPayload = xmlSoapRequest.SelectSingleNode("//Envelope/Body/GetRequisitionByDateResponse/").InnerText;
          //    }
          //}
  
      }
      catch (Exception ex)
      {
          DumpException(ex);
          this.ComponentMetaData.FireInformation(54, "", "Failed to deserialize: " + ex.Message + " Inner: " + ex.InnerException + " Source: " + ex.Source, "", 43, ref b);
      }
  
      return xmlResponse;
  
  }
  
  public static T DeserializeFromXml&lt;T&gt;(string xml)
  {
      T result;
  
      var ser = new XmlSerializer(typeof(T));
      using (var tr = new StringReader(xml))
      {
          result = (T)ser.Deserialize(tr);
      }
      return result;
  }
  </code></pre>
  
  <p>I am using c# classes generated by feeding a response into the XML to C# converter (<a href="http://xmltocsharp.azurewebsites.net/" rel="nofollow noreferrer">http://xmltocsharp.azurewebsites.net/</a>). Unfortunately it appears the classes are too complex to put here (posts have a 30k character limit), so it has been pasted here:
  <a href="http://txt.do/d91eo" rel="nofollow noreferrer">http://txt.do/d91eo</a></p>
  
  <p>I also pasted an example response:
  <a href="http://txt.do/d91eb" rel="nofollow noreferrer">http://txt.do/d91eb</a></p>
  
  <p>I have consulted the wsdl and it appears that many DateTime fields are being read as strings through the converter. I am not sure if this is an issue, but I have tried to do my best to replace those data types and the error persisted.</p>
  
  <p>Here is a screenshot of my error:
  <a href="https://imgur.com/a/objJq" rel="nofollow noreferrer">http://imgur.com/a/objJq</a></p>
  
  <p>Other things I have tried:</p>
  
  <p>Replacing invalid characters throughout the xml document (I found that it is doing this already, except in the case of some of the "'" characters).</p>
  
  <p>Removed namespaces.</p>
  
  <p>Marked all the classes as Serializable.</p>
  
  <p>The Web Services object within SSIS (throws an error and doesn't let me enter any variables to send).</p>
  
  <p>Regenerated the class list with a number of variants of the return result.</p>