При использовании Mono версии 2.10.5 следующий код завершается ошибкой в любом документе XML:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml.Linq;
namespace TestXDocument
{
class MainClass
{
public static void Main (string[] args)
{
Stream s = File.Open("Settings.xml", FileMode.Open);
XDocument d = XDocument.Load(s, LoadOptions.PreserveWhitespace);
s.Close();
d.Save("Settings.xml");
}
}
}
Это происходит только в том случае, если XDocument.Load использует LoadOptions.PreserveWhitespace. Любые идеи о том, как обойти это, или решить проблему?
Протестировано на Linux Mint 12 и Ubuntu 11.10.
Вот исключение:
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.XDocument.Save (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.Save (System.String filename, SaveOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.Save (System.String filename) [0x00000] in <filename unknown>:0
at TestXDocument.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[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.XDocument.Save (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.Save (System.String filename, SaveOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.Save (System.String filename) [0x00000] in <filename unknown>:0
at TestXDocument.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0