K
Keith
Hello all,
I have a C# Windows Forms app. It is in namespace App.GUI. It builds to Nav.exe. I have entered an application level setting using the designer. Its type is string, name is "FOO" and value is "monkey". I've tried the following ways to retrieve the value and only one works:
//Returns null
Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
string monkey = config.AppSettings.Settings["FOO"];
//Returns null - I know this is deprecated
string monkey = ConfigurationSettings.AppSettings["FOO"];
//Returns null
string monkey = ConfigurationManager.AppSettings["FOO"];
//Returns correct value
string monkey = global::App.GUI.Properties.Settings.Default["FOO"].ToString();
The Nav.exe.config file is in the right place. The Configuration object (first example) contains the correct path and its HasFile property is True. A Label bound to FOO displays the correct value. Looking at the XML in Nav.exe.config shows
<applicationSettings>
<App.GUI.Properties.Settings>
<setting name="FOO" serializeAs="String">
<value>monkey</value>
</setting>
</App.GUI.Properties.Settings>
</applicationSettings>
So what am I doing wrong? Using global:: isn't very helpful when trying to get at these settings from another assembly (BTW all the methods that fail in the .exe fail identically in satellite assemblies)
Any helpful advice or suggestions are greatly appreciated.
Keith
I have a C# Windows Forms app. It is in namespace App.GUI. It builds to Nav.exe. I have entered an application level setting using the designer. Its type is string, name is "FOO" and value is "monkey". I've tried the following ways to retrieve the value and only one works:
//Returns null
Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
string monkey = config.AppSettings.Settings["FOO"];
//Returns null - I know this is deprecated
string monkey = ConfigurationSettings.AppSettings["FOO"];
//Returns null
string monkey = ConfigurationManager.AppSettings["FOO"];
//Returns correct value
string monkey = global::App.GUI.Properties.Settings.Default["FOO"].ToString();
The Nav.exe.config file is in the right place. The Configuration object (first example) contains the correct path and its HasFile property is True. A Label bound to FOO displays the correct value. Looking at the XML in Nav.exe.config shows
<applicationSettings>
<App.GUI.Properties.Settings>
<setting name="FOO" serializeAs="String">
<value>monkey</value>
</setting>
</App.GUI.Properties.Settings>
</applicationSettings>
So what am I doing wrong? Using global:: isn't very helpful when trying to get at these settings from another assembly (BTW all the methods that fail in the .exe fail identically in satellite assemblies)
Any helpful advice or suggestions are greatly appreciated.
Keith