By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,872 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,872 IT Pros & Developers. It's quick & easy.

Deserialization Error

P: n/a
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();
}
}

Mar 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Have you defined the Holiday_List class?

If so can you post it.

Dickster

Mar 20 '06 #2

P: n/a
Post the XML as well

Mar 20 '06 #3

P: n/a
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

Mar 20 '06 #4

P: n/a
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!

Mar 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.