This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 8592 - System.Configuration.ApplicationSettingsBase performs Reset() for user.config instead of proper Reload() behavior described on MSDN
Summary: System.Configuration.ApplicationSettingsBase performs Reset() for user.config...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Configuration (show other bugs)
Version: Trunk
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-26 05:21 UTC by Kei Nakazawa
Modified: 2012-11-27 02:16 UTC (History)
2 users (show)

See Also:
Tags:


Attachments
fix for bug 8592 (6.79 KB, patch)
2012-11-27 01:22 UTC, Kei Nakazawa
Details | Diff

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]

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