Bug 8533

Summary: System.Configuration.ApplicationSettingsBase screws user.config file when used by multiple child classes
Product: [Mono] Class Libraries Reporter: Kei Nakazawa <nakazawa-k>
Component: System.ConfigurationAssignee: Bugzilla <bugzilla>
Severity: normal CC: atsushi, mono-bugs+mono
Priority: ---    
Version: master   
Target Milestone: Untriaged   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: see "description" for detail
fix bug 8533

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 {
        public string TestKey1OnHolder1 { get { return (string)this["TestKey1OnHolder1"] ?? ""; } set { this["TestKey1OnHolder1"] = value; } }
    class ConfHolder2 : ApplicationSettingsBase
        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";

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]
            <setting name="TestKey1OnHolder2" serializeAs="String">
            <setting name="TestKey1OnHolder1" serializeAs="String">
 [/MS runtime]
 [Mono runtime]
  <setting name="TestKey1OnHolder1" serializeAs="String">
  <setting name="TestKey1OnHolder2" serializeAs="String">
 [/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]