Mono - XDocument.Load не работает с LoadOptions.PreserveWhitespace

При использовании 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 
5
задан Drew DeVault 6 February 2012 в 10:37
поделиться