title: System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1 - Valid XML file?
body: <p>I am receiving this error when trying to parse an xml from a  byte array.</p>
  
  <pre><code>System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1
  </code></pre>
  
  <p>The failing code in question is:</p>
  
  <pre><code>public Packet PacketProcessor(Packet packet, out DeviceVerifyStep step, out string device_model, out string device_sn)
      {
          step = DeviceVerifyStep.None;
          device_model = null;
          device_sn = null;
  
          XmlDocument doc = new XmlDocument();
          try
          {
              string msg_xml = Encoding.ASCII.GetString(packet.body);
              Console.WriteLine(msg_xml);
              doc.LoadXml(msg_xml);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex);
              return null;
          }
  </code></pre>
  
  <p>And the XML it is failing to parse in hex is</p>
  
  <pre><code>3c3f786d6c2076657273696f6e3d22312e30223f3e3c4d6573736167653e3c5465726d696e616c547970653e45433530303c2f5465726d696e616c547970653e0d0a3c5465726d696e616c49443e313c2f5465726d696e616c49443e0d0a3c44657669636553657269616c4e6f3e6e756c6c65643c2f44657669636553657269616c4e6f3e0d0a3c526571756573743e4c6f67696e526571756573743c2f526571756573743e0d0a3c2f4d6573736167653e00
  </code></pre>
  
  <p>Which when converted to ASCII is:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;&lt;Message&gt;&lt;TerminalType&gt;EC500&lt;/TerminalType&gt;
  &lt;TerminalID&gt;1&lt;/TerminalID&gt;
  &lt;DeviceSerialNo&gt;nulled&lt;/DeviceSerialNo&gt;
  &lt;Request&gt;LoginRequest&lt;/Request&gt;
  &lt;/Message&gt;?
  </code></pre>
  
  <p>I have removed the last two bytes <code>3e00</code> which I believe may be causing an invalid XML with no success.</p>
  
  <p>Any help would be appreciated.</p>