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)

See Also:
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 | Diff

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 ***

Note You need to log in before you can comment on or make changes to this bug.