title: There is an error in XML document (27, 4) when deserializing XML from MemoryStream class
body: <p>When receiving XML data from an API I get this exception thrown.</p>
  
  <p>{"The string '' is not a valid AllXsd value."}</p>
  
  <p>There is an error in XML document (27, 4)</p>
  
  <p>The XML data looks OK and I have used this code before for parsing similar XML. So I'm not sure what causing the exception.</p>
  
  <p>The returned XML is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
  &lt;agentInventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:N1="demo.org.uk/demo/CustomsStatus" xmlns:N2="demo.org.uk/demo/UnLocation" xmlns:N3="demo.org.uk/demo/AirCarrier" xmlns="demo.org.uk/demo/AgentInventory"&gt;
    &lt;shed&gt;TAX&lt;/shed&gt;
    &lt;arrivalPort&gt;
      &lt;N2:iataPortCode&gt;LHR&lt;/N2:iataPortCode&gt;
    &lt;/arrivalPort&gt;
    &lt;masterAirwayBillPrefix&gt;125&lt;/masterAirwayBillPrefix&gt;
    &lt;masterAirwayBillNumber&gt;25051155&lt;/masterAirwayBillNumber&gt;
    &lt;nominatedAgent&gt;DRB&lt;/nominatedAgent&gt;
    &lt;originPort&gt;
      &lt;N2:iataPortCode&gt;BOS&lt;/N2:iataPortCode&gt;
    &lt;/originPort&gt;
    &lt;destinationPort&gt;
      &lt;N2:iataPortCode&gt;LHR&lt;/N2:iataPortCode&gt;
    &lt;/destinationPort&gt;
    &lt;airCarrier&gt;
      &lt;N3:carrierCode&gt;BA&lt;/N3:carrierCode&gt;
     &lt;/airCarrier&gt;
    &lt;flightNumber&gt;123&lt;/flightNumber&gt;
    &lt;flightDate&gt;2011-05-25T00:00:00Z&lt;/flightDate&gt;
    &lt;npx&gt;10&lt;/npx&gt;
    &lt;npr&gt;0&lt;/npr&gt;
    &lt;grossWeight&gt;123.0&lt;/grossWeight&gt;
    &lt;goodsDescription&gt;BOOKS&lt;/goodsDescription&gt;
    &lt;sdc&gt;T&lt;/sdc&gt;
    &lt;status1Set&gt;&lt;/status1Set&gt;
    &lt;status2Set&gt;true&lt;/status2Set&gt;
    &lt;ccsCreationTime&gt;2011-05-25T21:17:00Z&lt;/ccsCreationTime&gt;
    &lt;customsStatus&gt;
      &lt;N1:code&gt;CC&lt;/N1:code&gt;
      &lt;N1:statusText&gt;Customs cleared&lt;/N1:statusText&gt;
    &lt;/customsStatus&gt;
    &lt;customsSummaryText&gt;TRED CLEARANCE&lt;/customsSummaryText&gt;
    &lt;customsSummaryTime&gt;2011-05-25T21:30:00Z&lt;/customsSummaryTime&gt;
    &lt;agentReference&gt;RS CFSP &lt;/agentReference&gt;
    &lt;isErtsPreArrival&gt;false&lt;/isErtsPreArrival&gt;
    &lt;isAgentPreArrival&gt;false&lt;/isAgentPreArrival&gt;
    &lt;isDeleted&gt;false&lt;/isDeleted&gt;
    &lt;finalised&gt;&lt;/finalised&gt;
    &lt;createdOn&gt;2011-05-25T21:17:18.167Z&lt;/createdOn&gt;
    &lt;modifiedOn&gt;2011-05-25T21:30:20.37Z&lt;/modifiedOn&gt;
      &lt;/agentInventory&gt;
  </code></pre>
  
  <p>The code used to deserialize this XML looks like this:</p>
  
  <pre><code> var storeXmlInventoryReturnData = returnInventoryData.ReturnValue;
  
          if (storeXmlInventoryReturnData != null)
          {
  
              //DeSerialize XML from variable
              agentInventory myInventoryResponse = null;
  
              XmlSerializer xmlSerializer = new XmlSerializer(typeof(agentInventory));
              MemoryStream memStream = new MemoryStream(Encoding.UTF8.GetBytes(storeXmlInventoryReturnData));
              myInventoryResponse = (agentInventory)xmlSerializer.Deserialize(memStream);
  
              Console.WriteLine(
               @"\n\n\n INVENTORY RETURN DATA FOR AWB: {0}-{1} \n\n 
                            Destination Port: {2} \n 
                            Arrival Port: {3} \n 
                            Carrier: {4} \n 
                            Flight No: {5} \n 
                            Flight Date: {6} \n 
                            Customers Status: {7} \n 
                            NPX: {8} \n
                            NPR {9} \n
                            SDC Code: {10}                              
                            \n\n Hit any key to exit...."
                  ,
  
                  myInventoryResponse.masterAirwayBillPrefix,
                 myInventoryResponse.masterAirwayBillNumber,
                  myInventoryResponse.destinationPort,
                  myInventoryResponse.arrivalPort,
                  myInventoryResponse.airCarrier,
                  myInventoryResponse.flightNumber,
                 myInventoryResponse.flightDate,
                 myInventoryResponse.customsStatus,
                  myInventoryResponse.npx,
                  myInventoryResponse.npr,
                  myInventoryResponse.sdc,
                 myInventoryResponse.grossWeight,
                  myInventoryResponse.goodsDescription
                      );
              Console.ReadLine();
          }
          else
          {
              Console.Write("No data returned");
          }
  </code></pre>
  
  <p>The line that throws the exception is</p>
  
  <pre><code>myInventoryResponse = (agentInventory)xmlSerializer.Deserialize(memStream);
  </code></pre>