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" ?>
 <add name="XmlSerialization.Compilation" value="1" />