简体   繁体   中英

C# - Deserializing xml string, there is an error in xml document (1,2)

I am trying to deserialize a xml string in C# using the following

XmlSerializer serializer = new XmlSerializer(typeof(Application));

App = (Application)serializer.Deserialize(xmlString);

It all works well when the xml is pretty printed, but when i have the whole xml in a single line deserializing fails with the error

There is an error in XML document (1, 2). Name cannot begin with the '.' character, hexadecimal value 0x00. Line 1, position 2."

I've checked that the xml is valid as such.

Any one knows what can be done to overcome this problem?

Chances are that you loading UTF-16 file as UTF-8 and as result every second character is 0.

If it is true - it could happen if you saved your original XML without BOM (byte order mark) or explicitly using wrong encoding while openeing file...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM