Bug 3231 - XDocument.Load fails with LoadOptions.PreserveWhitespace
Summary: XDocument.Load fails with LoadOptions.PreserveWhitespace
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-02-06 04:34 UTC by Drew DeVault
Modified: 2012-03-08 08:43 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Drew DeVault 2012-02-06 04:34:45 UTC
Using Mono version 2.10.5, the following code fails on any XML document:

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);

This only happens if XDocument.Load uses LoadOptions.PreserveWhitespace.
Comment 1 Atsushi Eno 2012-03-08 08:43:47 UTC
Surprisingly this was caused by XmlTextWriter and XmlWriterSettings part. This should be fixed in git master (2927d27). Thanks for the report.