Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserialization error in XML document(1,1)

I have an XML file that I deserialize, the funny part is the XML file is the was serialized using the following code:

enter code here
var serializer = new XmlSerializer(typeof(CommonMessage));
var writer = new StreamWriter("OutPut.txt");
serializer.Serialize(writer, commonMessage);
writer.Close();

And i m trying to deserialized it again to check if the output match the input. anyhow here is my code to deserialize:

var serializer = new XmlSerializer(typeof(CommonMessage));
var reader = new StringReader(InputFileName);
CommonMessage commonMessage = (CommonMessage)serializer.Deserialize(reader);
like image 877
jprbest Avatar asked Jan 18 '11 16:01

jprbest


People also ask

What is Deserialization in XML?

Deserialization is the process of reading an XML document and constructing an object that is strongly typed to the XML Schema (XSD) of the document. Before deserializing, an XmlSerializer must be constructed using the type of the object that is being deserialized.

What is Deserialize error?

Hence when the XML stream comes in, and the proxy tried to de-serialize (parse) to create ABAP object, it fails. This is called DESERIALIZATION ERROR. You mentioned that you could successfully get a single record, while when multiple records came from server, it failed.


2 Answers

Replace StringReader with StreamReader and it will work fine. StringReader reads value from the string (which is file name in your case).

like image 89
Alexei Levenkov Avatar answered Oct 17 '22 11:10

Alexei Levenkov


I just had the same error message but different error source. In case someone has the same problem like me. I chopped off the very first char of my xml string by splitting strings. And the xml string got corrupted:

"?xml version="1.0" encoding="utf-16"?> ..." // my error
"<?xml version="1.0" encoding="utf-16"?> ..." // correct

(1,1) means basically first char of the first line is incorrect and the string can't be deserialized.

like image 2
Bitterblue Avatar answered Oct 17 '22 09:10

Bitterblue