Bug 8592

Summary: System.Configuration.ApplicationSettingsBase performs Reset() for user.config instead of proper Reload() behavior described on MSDN
Product: [Mono] Class Libraries Reporter: Kei Nakazawa <nakazawa-k>
Component: System.ConfigurationAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
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: fix for bug 8592

Description Kei Nakazawa 2012-11-26 05:21:50 UTC
Mono version of Reload() method actually resets configuration values instead of reloading from persistent storage as described: http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase.reload(v=vs.80).aspx
repro code:

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

namespace ApplicationSettingsBaseBehaviorTest
{
    class ConfHolder1 : ApplicationSettingsBase {
        [UserScopedSetting]
        public string TestKey1OnHolder1 { get { return (string)this["TestKey1OnHolder1"] ?? ""; } set { this["TestKey1OnHolder1"] = value; } }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var holder = new ConfHolder1();
            holder.TestKey1OnHolder1 = "candy";
            holder.Save();
            Console.WriteLine(holder.TestKey1OnHolder1 == "candy" ? "ok" : "not ok");
            holder.TestKey1OnHolder1 = "donut";
            Console.WriteLine(holder.TestKey1OnHolder1 == "donut" ? "ok" : "not ok");
            holder.Reload();
            Console.WriteLine(holder.TestKey1OnHolder1 == "candy" ? "ok" : "not ok");
            holder.Reset();
            Console.WriteLine(holder.TestKey1OnHolder1 == "" ? "ok" : "not ok");
        }
    }
}

MS Runtime output:
ok
ok
ok
ok

Mono (master/5d436f9) Runtime output:
ok
ok
not ok
ok

this issue is realted to https://bugzilla.xamarin.com/show_bug.cgi?id=8533 but is independent.
Comment 1 Kei Nakazawa 2012-11-27 01:22:18 UTC
Created attachment 3017 [details]
fix for bug 8592

this patch satisfies needed behavior
 * Reset() should not flush current data to persistent storage
 * Reset() should restore default values by property definitions
 * Reload() should not be an alias for Reset()

I know there might be a better fix but not yet familiar with Mono tweaking manner. Any comments would be appreciated.
Comment 2 Atsushi Eno 2012-11-27 02:16:44 UTC
Applied the fix. Thanks!

[master 2ce7995]