- Mono - XDocument.Load fails with LoadOptions.PreserveWhitespace
- 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");
- }
- }
- }
- 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
- using System;
- using System.Xml.Linq;
- using System.IO;
- namespace Test
- {
- class MainClass
- {
- public static void Main (string[] args)
- {
- using (var s = new StreamReader("E:\expected.xml"))
- {
- XDocument d = XDocument.Load(s, LoadOptions.PreserveWhitespace);
- s.Close();
- d.Save("e:\Settings.xml");
- }
- }
- }
- }
- d.Root.Save("Settings1.xml");