Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, February 11, 2016 6:22 AM
Hi
In an existing program with a settings class like below, I added a new setting with the default value as True.
I then deleted the relevant user.config from C:\Users\me>\AppData\Local\Schneider_Electric
HOWEVER when I start, the setting is coming through as FALSE. I know I have the correct user.config because when I set the setting to true and save, the user.config gets updated correctly.
>> I am completely stumped on why this does work when other settings which are set True come through,
>> Ideas ?
e.g. trace as point of class being created
KernelOnMenu true bool
Language "Auto" string
ListGlobalStore false bool
MinorVersionSupport false bool <= should be true
Thanks in advance
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
...
... new setting
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool MinorVersionSupport {
get {
return ((bool)(this["MinorVersionSupport"]));
}
set {
this["MinorVersionSupport"] = value;
}
} [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")] publicboolKernelOnMenu { get{ return((bool)(this["KernelOnMenu"]));
}
set{
this["KernelOnMenu"] = value;
}
}
All replies (3)
Monday, February 15, 2016 5:10 AM âś…Answered
I found the answer, hinted at in https://msdn.microsoft.com/en-us/library/8eyb2ct1(v=vs.110).aspx
It turns out that <app>.exe.config is the MASTER copy, i.e. these code defaults are ignored if this exists
So you have two options :
- delete <app>.exe.config from your bin area
- edit your app.config to correspond with the default settings in your code
I am sure there are meant to be advantages to this approach, but for me, it is only asking for trouble having two systems running.
regards
Friday, February 12, 2016 5:59 AM
Hi Greg B Roberts,
Have you found MinorVersionSupport setting section in your config?
<setting name="MinorVersionSupport" serializeAs="String">
<value>True</value>
</setting>
Have you assign new value to MinorVersionSupport in other place of your application? For example:
Properties.Settings.Default.MinorVersionSupport = false;
Best Regards,
Li Wang
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Friday, February 12, 2016 6:51 AM
Hi
On first question yes, it is in the code sample above
On the 2nd question yes there is code to change the setting when you run the options form however the options form is populated with the settings first when fired.
The first call to the settings occurs as a consequence of code below.
Note: on a fresh run where user.config has been deleted the entries for these settings do not appear. However of exit of the program the settings show up as this is a code call to save settings.
At start the set code does not get called and the value is false
>> So I suppose it would be good to know what actual function is processing the Attributes at startup to find out what is going on ?
using(MutexsingleInstanceMutex = newMutex(true, mutexName, outownershipGranted)
{
if(ownershipGranted)
{
if(Settings.Default.Language != "Auto") <= First call and new param false
{