Recently, for some need I found a very strange error. Trying to read an XML with XmlDocument got the following error: "Data at the root level is invalid. Line 1, position 1. "
The string obtained came from a stream, which he read from a party.
After several twists and turns, I finally found the casue of the problem: write the original stream, was doing the following :
var writer = new StreamWriter (stream, Encoding.Unicode)brought
writer.Write (text);
The problem is that, by the way was being read across the stream ( external code, as revised by the friend Lutz!) was misinterpreting the use of Unicode mark at the beginning of the string.
To fix this, just replace the lines in setting up and using the StreamWriter, by:
var writer = new StreamWriter (stream, new UnicodeEncoding (false, false));
writer.Write (text);
This way to create the encoding, it indicates that the mark should be included Unicode string at the beginning of, solving the above problem
I hope to help someone with this.
Greetings! Zaiden
0 comments:
Post a Comment