views:

735

answers:

3

During development I've seen xml read errors like this more than once:

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

What exactly does (2, 2) refer to? Is it line 2 in the xml file? Line 2, token 2, what?

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

Edit: here are the first 2 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"&gt;

So it would be complaining on the 'T' character on the 2nd line? This is a class I just serialized, and it is well formed. When deserializing, I think it doesn't like something in the class... and that might explain why it stops at the T in TestSession. It would be nice if it told you what it didn't like.

+1  A: 

It's line 2, character 2.

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

John Saunders
+1. Or notepad2. Or emacs, or etc etc etc. OFten it's a really obvious invalid bit of XML.
Cheeso
A: 

Try some xml validation tool to validate your xml file/contents, Do a google, and you'll find some.

J.W.
+1  A: 

It's (line, character) and begins at 1 (not 0 based).

You should examine the InnerException to get a more precise error message. Looking at your example, it could be something like:

"<TestSession> was not expected."

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

Mehmet Ergut