.net: how to debug XmlSerializer.Deserialize errors?

During development, I saw xml read errors like this more than once:

TestData.ReadFromXml: xml Deserialization Error: There is an error (2, 2) in the XML document ..

What exactly does (2, 2) mean? Is this line 2 in the xml file? Line 2, token 2, what?

Are there any debugging options that I can add to shed more light on the problem?

Edit: here are the first two lines:

<?xml version="1.0" encoding="utf-8"?>
<TestSession xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

So he will complain about the character “T” on the 2nd line? This is a class that I just serialized and it is well formed. When deserializing, I think it doesn't like something in the class ... and this may explain why it stops at T in TestSession. It would be nice if he told you that he did not like it.

+3
source share
3 answers

It (string, character) and starts at 1 (not based on 0).

You should study InnerExceptionto get a more accurate error message. Looking at your example, it could be something like:

"<TestSession> was not expected."

You can also change the serialized name by applying XmlRootAttributeto your class.

+2
source

This is line 2, character 2.

I recommend that you open the XML file in Visual Studio, and then look at the Errors window to see if it really complains.

+1
source

xml xml /. google, .

0

Source: https://habr.com/ru/post/1705914/


All Articles