Why “Data at the root level is invalid. Line 1, position 1.” for XML Document?

前端 未结 5 609
暗喜
暗喜 2020-11-30 08:34

I am using a third-party DLL which transmits an XML document over the internet.

Why would the DLL be throwing the following exception?

Data at

5条回答
  •  误落风尘
    2020-11-30 09:20

    I eventually figured out there was a byte mark exception and removed it using this code:

     string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
        if (xml.StartsWith(_byteOrderMarkUtf8))
        {
            var lastIndexOfUtf8 = _byteOrderMarkUtf8.Length-1;
            xml = xml.Remove(0, lastIndexOfUtf8);
        }
    

提交回复
热议问题