System.InvalidOperationException: There is an error in XML document (line, column)

Have you ever received this error, If yes then you must had a tough time to identify the actual issue.

When we Deserialize(), If the XML is not valid or if there is any mismatch in expected name or data type then we will be getting  an error message like below,

System.InvalidOperationException: There is an error in XML document (<line>, <column>).

In this case the InnerException is not that much helpful to identify the root cause.

So how do we Identify the actual issue, Here we go.

Just enable the diagnostic switch for  XmlSerialization.Compilation in config file. Once you do that then you can easily debug the generated file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 ...
 <system.diagnostics>
 <switches>
 <add name="XmlSerialization.Compilation" value="1" />
 </switches>
 </system.diagnostics>
 ...
</configuration>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s