Bug 38460 - Improvements to System.Xml caused CustomizableFileSettingsProvider to create corrupt xml files.
Summary: Improvements to System.Xml caused CustomizableFileSettingsProvider to create ...
Status: RESOLVED DUPLICATE of bug 36388
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Configuration (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2016-02-04 16:37 UTC by Tom Hindle
Modified: 2016-02-25 11:56 UTC (History)
2 users (show)

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


Attachments
Possible/Suggested fix. (754 bytes, patch)
2016-02-04 16:54 UTC, Tom Hindle
Details


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:
Status:
RESOLVED DUPLICATE of bug 36388

Description Tom Hindle 2016-02-04 16:37:04 UTC
Previously (eg mono 3.2.8) assigning to XmlElement.InnerXml would strip off any xml declaration.

mono 4.2.1 no longer does this and matches .dot net behaviour. (good!)

For example:

var d = new XmlDocument();
var e  = d.CreateElement ("test");
e.InnerXml = "<?xml version=\"1.0\" encoding=\"utf-16\"?><test>hi</test>";
Console.WriteLine ("inner xml = {0}", e.InnerXml);

In Mono 3.2.8 displays "<test>hi</test>"

in mono 4.2.1 displays "<?xml version="1.0" encoding="utf-16"?><test>hi</test>"

However this causes problems where the stripping behaviour is assumed.

From example in 
mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs


switch (value.Property.SerializeAs) {
case SettingsSerializeAs.Xml:
   element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
   break;

Invalid xml can now be written to xml file causing corrupt xml documents.
Comment 1 Tom Hindle 2016-02-04 16:54:35 UTC
Created attachment 14899 [details]
Possible/Suggested fix.

Fix the problem after it happened rather than stripping the string before hand.
Comment 2 marcos.henrich 2016-02-25 11:56:21 UTC
Hi Tom,

Thanks for the detailed bug report.

A fix for this is already on master, and mono-4.4.0-branch so this should be fixed in cycle 7.

You can look at #36388 for more details.

*** This bug has been marked as a duplicate of bug 36388 ***