I am struggling with some Monodroid code that should be simple, but is causing an unexpected exception.开发者_JS百科 The code throws an exception when I try to invoke SelectNodes() on an XmlDocument object.
This is the code:
XmlDocument handXmlDocument = new XmlDocument();
XmlDeclaration dec = handXmlDocument.CreateXmlDeclaration("1.0", null, null);
handXmlDocument.AppendChild(dec);
XmlElement root = handXmlDocument.CreateElement("friendslist");
handXmlDocument.AppendChild(root);
XmlElement friendElement = handXmlDocument.CreateElement("friend");
friendElement.SetAttribute("locationx", "35");
friendElement.SetAttribute("locationy", "46");
friendElement.SetAttribute("phone", "4085556803");
root.AppendChild(friendElement);
XmlNodeList friendNodeList = handXmlDocument.SelectNodes("/friendslist/friend");
and here is the exception:
E/mono ( 365): [0x45eec0:] EXCEPTION handling: System.TypeInitializationException: An exception was thrown by the type initializer for System.Console E/FriendsView( 365): Exception parsing XML document: An exception was thrown by the type initializer for System.Console E/FriendsView( 365): Inner exception parsing XML document: System.ExecutionEngineException: SIGILL E/FriendsView( 365): at System.Console..cctor () [0x00019] in /Users/plasma/Work/mono-android-trunk/mcs/class/corlib/System/Console.cs:127
I have no idea why System.Console is involved here! Thanks for any help, Martin
Just adding this in the hopes it might help anyone else who hits the same problem. It turns out that this was a bug in Monodroid 1.0.8980 which was fixed by the time of Monodroid 1.0.9186. Upgrading to the new release fixed my problem.
精彩评论