Bug 8533 - System.Configuration.ApplicationSettingsBase screws user.config file when used by multiple child classes
Summary: System.Configuration.ApplicationSettingsBase screws user.config file when use...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Configuration (show other bugs)
Version: master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-20 22:13 UTC by Kei Nakazawa
Modified: 2012-11-27 05:53 UTC (History)
2 users (show)

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


Attachments
see "description" for detail (1.46 KB, application/zip)
2012-11-20 22:13 UTC, Kei Nakazawa
Details
fix bug 8533 (6.11 KB, patch)
2012-11-27 04:11 UTC, Kei Nakazawa
Details

Description Kei Nakazawa 2012-11-20 22:13:24 UTC
Created attachment 2981 [details]
see "description" for detail

repro. code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace ApplicationSettingsBaseBehaviorTest
{
    class ConfHolder1 : ApplicationSettingsBase {
        [UserScopedSetting]
        public string TestKey1OnHolder1 { get { return (string)this["TestKey1OnHolder1"] ?? ""; } set { this["TestKey1OnHolder1"] = value; } }
    }
    class ConfHolder2 : ApplicationSettingsBase
    {
        [UserScopedSetting]
        public string TestKey1OnHolder2 { get { return (string)this["TestKey1OnHolder2"] ?? ""; } set { this["TestKey1OnHolder2"] = value; } }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var holder1 = new ConfHolder1();
            var holder2 = new ConfHolder2();
            holder1.TestKey1OnHolder1 = "candy";
            holder2.TestKey1OnHolder2 = "donut";
            holder1.Save();
            holder2.Save();
        }
    }
}

multi sectioned XML should be generated by this code like MS runtime does, but Mono(tested on 3.0.0beta/master:5d436f92c) runtime
 - properly generates "sectionGroup" node
 - doesn't generate "section" node for ConfHandler2 inside "sectionGroup"
 - doesn't generate proper node for ConfHandler2 inside "userSettings"
 - put all values together into ConfHolder1 space inside "userSettings", which should be splited into ConfHolder1 subsection and ConfHolder2 subsection (*1: please refer XML snippet below)

I suspect https://bugzilla.xamarin.com/show_bug.cgi?id=2673 report is triggered by this behavior(wrong save -> internal error on next load).

*1: XML snippet
 [MS runtime]
    <userSettings>
        <ApplicationSettingsBaseBehaviorTest.ConfHolder2>
            <setting name="TestKey1OnHolder2" serializeAs="String">
                <value>donut</value>
            </setting>
        </ApplicationSettingsBaseBehaviorTest.ConfHolder2>
        <ApplicationSettingsBaseBehaviorTest.ConfHolder1>
            <setting name="TestKey1OnHolder1" serializeAs="String">
                <value>candy</value>
            </setting>
        </ApplicationSettingsBaseBehaviorTest.ConfHolder1>
    </userSettings>
 [/MS runtime]
 [Mono runtime]
  <userSettings><ApplicationSettingsBaseBehaviorTest.ConfHolder1>
  <setting name="TestKey1OnHolder1" serializeAs="String">
    <value>candy</value>
  </setting>
  <setting name="TestKey1OnHolder2" serializeAs="String">
    <value>donut</value>
  </setting>
</ApplicationSettingsBaseBehaviorTest.ConfHolder1></userSettings>
 [/Mono runtime]

attached zip contains:
 - Program.cs : repro code(as seen above)
 - user.config.ms : proper user.config file generated by MS runtime(.NET 4.0)
 - user.config.mono : wrong user.config file generated by Mono runtime(master:5d436f92c)
Comment 1 Kei Nakazawa 2012-11-27 04:11:17 UTC
Created attachment 3019 [details]
fix bug 8533

this patch contains
 * test cases for regression testing
 * fix handling multiple userSections creation
 * suppress mixing up other userSections' data

generated against master/2ce79959
Comment 2 Atsushi Eno 2012-11-27 05:53:33 UTC
Thanks, applied this patch too.

[master 05d46a8]

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.


Create a new report for Bug 8533 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


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.

Related Links: