all groups > dotnet xml > march 2006 >
You're in the

dotnet xml

group:

Deserialization Error



Deserialization Error Doug
3/20/2006 7:46:23 AM
dotnet xml: Hello,

I am trying to deserialize a very simply XML file and have the
following code to do it. When I run the code, I keep getting this
error: "An unhandled exception of type
'System.InvalidOperationException' occurred in system.xml.dll.
Additional information: There is an error in XML document (4, 2)."

The thing I don't get is that this code is used for other XML files in
the department just fine and as far as I can tell there is nothing
wrong with my XML. It validates just fine. Does anyone know what this
is telling me? What does the 4,2 mean?

FileStream fileStream = null;
XmlTextReader xmlReader = null;
Holiday_List _dataMap;

try
{
string file = Path.Combine(Directory.GetCurrentDirectory(),
"HolidayInfo.xml");
fileStream = new FileStream(file, FileMode.Open);
xmlReader = new XmlTextReader(fileStream , XmlNodeType.Document,
null);
XmlSerializer serializer = new XmlSerializer(typeof(Holiday_List));
_dataMap = (Holiday_List)serializer.Deserialize(xmlReader );
return _dataMap;
}
finally
{
if (fileStream != null)
{
fileStream.Close();
}
if (xmlReader != null)
{
xmlReader.Close();
}
}
Re: Deserialization Error dickster
3/20/2006 8:14:48 AM
Have you defined the Holiday_List class?

If so can you post it.

Dickster
Re: Deserialization Error dickster
3/20/2006 8:24:14 AM
Post the XML as well
Re: Deserialization Error a.wilco NO[at]SPAM gmail.com
3/20/2006 10:31:38 AM
There should be an innerexception with more detail (when the exception
occurs, click View detail, then expand to the InnerException property).

Post that also :) The 4,2 probably refers to where the error occured in
the text file
Re: Deserialization Error Doug
3/20/2006 11:28:45 AM
I got some help at work and figured it out. Holiday_List was the wrong
object to try to deserialize. There was another object called Holidays
which was the one I needed. I know that probably doesn't mean much to
anyone without seeing the schema on it, but that turned out to be the
problem. Thanks though!
AddThis Social Bookmark Button