[Mono-osx] Problem reading XML files:

Bart Masschelein masschel at gmail.com
Tue Jul 8 17:01:18 EDT 2008


Hi all,

I'm developing an application using C#. As IDE, I use Visual Studio,  
and also in Visual Studio I compile. Step by step, for every small  
improvement, I check if I can run the executable using Mono under OS  
X, as I want the application to be cross platform. Until now, all went  
fine, but now I encountered a small issue, reading an XML file. I use  
the following code, where xmlFile is a string to the xml file:

XmlDocument doc = new XmlDocument();
// Works
XmlTextReader reader = new XmlTextReader(xmlFile);
doc.Load(reader);
// Does not work in Mono
//doc.LoadXml(xmlFile);

As you can see in comments, doc.LoadXML(xlmFile) fails, reporting:

Unhandled Exception: System.Xml.XmlException: Text node cannot appear  
in this state.  Line 1, position 1.
   at Mono.Xml2.XmlTextReader.ReadText (Boolean notWhitespace) [0x00000]
   at Mono.Xml2.XmlTextReader.ReadContent () [0x00000]
   at Mono.Xml2.XmlTextReader.Read () [0x00000]
   at System.Xml.XmlTextReader.Read () [0x00000]
   at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader  
reader) [0x00000]
   at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader)  
[0x00000]
   at System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader)  
[0x00000]
   at System.Xml.XmlDocument.LoadXml (System.String xml) [0x00000]
   at XmlParser.XmlParser..ctor (System.String xmlFile) [0x00000]
   at GUI.Form1.XmlLocationButton_Click (System.Object sender,  
System.EventArgs e) [0x00000]
   at System.Windows.Forms.Control.OnClick (System.EventArgs e)  
[0x00000]
   at System.Windows.Forms.Button.OnClick (System.EventArgs e) [0x00000]
   at System.Windows.Forms.ButtonBase.OnMouseUp  
(System.Windows.Forms.MouseEventArgs mevent) [0x00000]
   at System.Windows.Forms.Button.OnMouseUp  
(System.Windows.Forms.MouseEventArgs mevent) [0x00000]
   at System.Windows.Forms.Control.WmLButtonUp  
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.Control.WndProc  
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.ButtonBase.WndProc  
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.Button.WndProc  
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.Control+ControlWindowTarget.OnMessage  
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.Control+ControlNativeWindow.WndProc  
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg,  
IntPtr wParam, IntPtr lParam) [0x00000]
   at System.Windows.Forms.XplatUICarbon.DispatchMessage  
(System.Windows.Forms.MSG& msg) [0x00000]
   at System.Windows.Forms.XplatUI.DispatchMessage  
(System.Windows.Forms.MSG& msg) [0x00000]
   at System.Windows.Forms.Application.RunLoop (Boolean Modal,  
System.Windows.Forms.ApplicationContext context) [0x00000]
   at System.Windows.Forms.Application.Run  
(System.Windows.Forms.ApplicationContext context) [0x00000]
   at System.Windows.Forms.Application.Run (System.Windows.Forms.Form  
mainForm) [0x00000]
   at GUI.Program.Main () [0x00000]

Initially I thought it might be because I don't comile using mcs, but  
looking at the track trace, you can see doc.LoadXml merely calls  
XmlReader. Since my code using the reader works, it looks like  
something else is at stake, maybe some initialization somewhere  
happening different?

I'm not really stuck, but I thought sharing this. If you want to test  
the error, you can try pointing to your iTunes XML file.

regards,

Bart


More information about the Mono-osx mailing list