Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 452
user560174 Avatar asked Apr 22 '11 16:04

user560174


People also ask

What is C in simple words?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C or C++ same?

While C and C++ may sound similar, their features and usage differ. C is a procedural programming language that support objects and classes. On the other hand C++ is an enhanced version of C programming with object-oriented programming support.


1 Answers

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...

like image 147
Alexei Levenkov Avatar answered Sep 27 '22 21:09

Alexei Levenkov