[Mono-list] Mono-Only XDocument.Save Error

Atsushi Eno atsushieno at veritas-vos-liberabit.com
Mon Feb 6 07:14:49 UTC 2012


I have one doubt that I think is likely the cause of the problem and 
also that prevents me from verifying it: you seem to have non-ASCII 
character in your XML you pasted in the message. This could be cause of 
the error e.g. inconsistent encoding input/output. A reproducible test 
case that everyone can examine is appreciated.

Atsushi Eno


> I can duplicate this problem on Linux Mint 12 and Ubuntu 11.10, but 
> Microsoft.NET on Windows 7 does not have the issue. The issue is that 
> my XDocument becomes corrupted the moment it loads, and cannot be 
> saved. Strangely, I am able to traverse it and manipulate it in 
> memory. The following code:
>
> Stream s = File.Open("example.xml", FileMode.Open);
> XDocument d = XDocument.Load(s);
> s.Close();
> d.Save("example.xml");
>
> Produces the following exception:
>
> [23:19:05] PartyCraft.CurrentDomain_UnhandledException: Error: 
> InvalidOperationException: This XmlWriter does not accept Text at this 
> state Prolog.
> [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: 
> This XmlWriter does not accept Text at this state Prolog.
> at System.Xml.XmlTextWriter.ShiftStateContent (System.String occured, 
> Boolean allowAttribute) [0x00000] in <filename unknown>:0
> at System.Xml.XmlTextWriter.WriteString (System.String text) [0x00000] 
> in <filename unknown>:0
> at System.Xml.DefaultXmlWriter.WriteString (System.String text) 
> [0x00000] in <filename unknown>:0
> at System.Xml.Linq.XText.WriteTo (System.Xml.XmlWriter w) [0x00000] in 
> <filename unknown>:0
> at System.Xml.Linq.XDocument.WriteTo (System.Xml.XmlWriter w) 
> [0x00000] in <filename unknown>:0
> at System.Xml.Linq.XNode.ToString (SaveOptions options) [0x00000] in 
> <filename unknown>:0
> at System.Xml.Linq.XNode.ToString () [0x00000] in <filename unknown>:0
> at PartyCraftServer.XmlSettings.set_Item (System.String key, 
> System.String value) [0x00000] in <filename unknown>:0
> at PartyCraftServer.Commands.SettingCommand.ExecuteCommand 
> (LibMinecraft.Server.RemoteClient client, System.String[] parameters) 
> [0x00000] in <filename unknown>:0
> at PartyCraftServer.Commands.Command.Execute 
> (LibMinecraft.Server.RemoteClient client, System.String command) 
> [0x00000] in <filename unknown>:0
> at PartyCraftServer.PartyCraft.Run () [0x00000] in <filename unknown>:0
> at PartyCraftServer.Program.Main (System.String[] args) [0x00000] in 
> <filename unknown>:0
>
> The same exception occurs on d.ToString();
>
> The XML that is being loaded looks like this:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <partyCraft>
> <server maxplayers="100">
> <motd>PartyCraft Test Server</motd>
> <messages>
> <death>
> <!--TODO-->
> <suicide>§e{0} killed themselves.</suicide>
> <creeper>§e{0} looked at a creeper funny.</creeper>
> </death>
> </messages>
> </server>
>
> <command>
> <alias>
> <setting>s</setting>
> </alias>
> </command>
>
> <plugins>
> <!--TODO-->
> <plugin>TestPlugin.dll</plugin>
> </plugins>
> </partyCraft>
>
> And when saved, even though an exception occurs, the document is 
> overwritten with this:
>
> <?xml version="1.0" encoding="utf-8" ?>
>
> This is the output from mono --version:
>
> Mono JIT compiler version 2.10.5 (Debian 2.10.5-1)
> Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. 
> www.mono-project.com
> TLS: __thread
> SIGSEGV: altstack
> Notifications: epoll
> Architecture: amd64
> Disabled: none
> Misc: softdebug
> LLVM: supported, not enabled.
> GC: Included Boehm (with typed GC and Parallel Mark)
>
> Any help would be appreciated.
>
> -- 
> Drew "Sir Cmpwn" DeVault
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list