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(); } }
Have you defined the Holiday_List class? If so can you post it. Dickster
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
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!
Don't see what you're looking for? Try a search.
|