472,958 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Yet another app.config question - Isn't this supposed to be easy?

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
Sep 20 '06 #1
5 5689
You should just be able to write
Properties.Settings.Default["FOO"].ToString();

Ciaran O'Donnell

"Keith" wrote:
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
Sep 21 '06 #2
Ciaran O''Donnell wrote:
You should just be able to write
Properties.Settings.Default["FOO"].ToString();
I believe that this always returns the *default* value and not
necessarily the value in the file. Look at the code behind file for
the settings. As you add settings, it inserts new properties to the
Settings class so you can declare an instance of this class and use it
for your settings. One benefit is that you don't specify your setting
using a string literal like "FOO" so you reduce the chance for a typo.

What we have done is something like this:

using App.UI.Properties;

Settings _settings = new Settings();
string value = _settings.FOO;

I'm not 100% sure this is necessary, but it works.

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
Sep 21 '06 #3
I appreciate the responses, however there seems to be something essential
I'm missing. Why don't the methods for loading config information directly
from the app.settings file actually work? All the examples on the net
simply load the file and get the settings by name and off they go. This
does NOT work for me in any way.

I can get settings via Properties.Settings in the project for the main
assembly, but what about satellites? Unless I pass in the settings
collection (or something similar) that information isn't available to them
since loading from the app.config doesn't work. They don't even work for
for the main assembly!

Has anyone actually used the ConfigurationManager successfully? How about
retrieving app.config information from a satellite assembly? MVP's I'd
appreciate some clarification here.

Thanks!

"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Ciaran O''Donnell wrote:
>You should just be able to write
Properties.Settings.Default["FOO"].ToString();

I believe that this always returns the *default* value and not
necessarily the value in the file. Look at the code behind file for
the settings. As you add settings, it inserts new properties to the
Settings class so you can declare an instance of this class and use it
for your settings. One benefit is that you don't specify your setting
using a string literal like "FOO" so you reduce the chance for a typo.

What we have done is something like this:

using App.UI.Properties;

Settings _settings = new Settings();
string value = _settings.FOO;

I'm not 100% sure this is necessary, but it works.

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

Sep 21 '06 #4
hello Keith,
I've discovered something that is almost certainly a bug in
ConfigurationManager, and is probably what you are running into.

Try this test:
create a config file with a simple key/value setting in it, and store
the file in c:\temp\configtest.exe.config.

then run

Configuration config =
OpenExeConfiguration("c:\\temp\configtest.exe.conf ig");
Console.WriteLine(config.FilePath);

You'll see that the filename is "c:\temp\configtest.exe.config.config".
Note the extra "config" extension! That file of course does not
exist, so the settings all come up empty.

OpenExeConfiguration checks for the existence of the file you specify,
so you can't work around this by coding
"OpenExeConfig("c:\temp\configtest.exe")

However, there is a clumsy workaround. Create 2 configuration files,
one named "configtest.exe.config" and the second named
"configtest.exe.config.config". The first one allows the OpenExeConfig
to succeed, and the second one is actually used for reading the values.
Odd one, huh? I just discovered this today. Think I'll make a
separate posting.
- Leo


Keith wrote:
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
------=_NextPart_000_00DE_01C6DCAD.1FAB49D0
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 3521

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hello all,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I have a C# Windows Forms app.&nbsp; It is in
namespace App.GUI.&nbsp; It builds to Nav.exe.&nbsp; I have entered an
application level setting using the designer.&nbsp; Its type is string, name is
"FOO" and value is "monkey".&nbsp; I've tried the following ways to retrieve the
value and only one works:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>//Returns null</FONT></DIV>
<DIV><FONT face=Arial size=2>Configuration config =
ConfigurationManager.OpenExeConfiguration(Assembly .GetEntryAssembly().Location);</FONT></DIV>
<DIV><FONT face=Arial size=2>string monkey =
config.AppSettings.Settings["FOO"];</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>//Returns null - I know this is
deprecated</FONT></DIV>
<DIV><FONT face=Arial size=2>string monkey =
ConfigurationSettings.AppSettings["FOO"];</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>//Returns null</FONT></DIV>
<DIV><FONT face=Arial size=2>string monkey =
ConfigurationManager.AppSettings["FOO"];</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>//Returns correct value</FONT></DIV>
<DIV><FONT face=Arial size=2>string monkey =
global::App.GUI.Properties.Settings.Default["FOO"].ToString();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>The Nav.exe.config file is in the right
place.&nbsp; The Configuration object (first example) contains the correct path
and its HasFile property is True.&nbsp; A Label bound to FOO displays the
correct value.&nbsp; Looking at the XML in Nav.exe.config shows</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial
size=2>&lt;applicationSettings&gt;<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;App.GUI.Properties.Settings&gt;<BR>&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&lt;setting
name="FOO"
serializeAs="String"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;value&gt;monkey&lt;/value&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/setting&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;
&lt;/App.GUI.Properties.Settings&gt;<BR>&nbsp;&nbsp;&nb sp;
&lt;/applicationSettings&gt;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>So what am I doing wrong?&nbsp; 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)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any helpful advice or suggestions are greatly
appreciated.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Keith</FONT></DIV></BODY></HTML>

------=_NextPart_000_00DE_01C6DCAD.1FAB49D0--
Oct 11 '06 #5
I'm not sure what is malfunctioning here, Keith.

I can tell you that I have an ASP.Net 2.0 application, and settings
retrieval from the Web.Config works fine using the strongly typed access
provided by the Settings object:

string monkey = <namespace>.Settings.Default.FOO;

And contrary to other posts, I do not just get the default values; If I
switch to a non-default value in the Web.Config, it materializes at runtime.
I wonder if there could be a bug that is specific to the non-web apps that
use exename.exe.config.
"Keith" <ke***@alh.comwrote in message
news:uj**************@TK2MSFTNGP05.phx.gbl...
>I appreciate the responses, however there seems to be something essential
I'm missing. Why don't the methods for loading config information directly
from the app.settings file actually work? All the examples on the net
simply load the file and get the settings by name and off they go. This
does NOT work for me in any way.

I can get settings via Properties.Settings in the project for the main
assembly, but what about satellites? Unless I pass in the settings
collection (or something similar) that information isn't available to them
since loading from the app.config doesn't work. They don't even work for
for the main assembly!

Has anyone actually used the ConfigurationManager successfully? How about
retrieving app.config information from a satellite assembly? MVP's I'd
appreciate some clarification here.

Thanks!

"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
>Ciaran O''Donnell wrote:
>>You should just be able to write
Properties.Settings.Default["FOO"].ToString();

I believe that this always returns the *default* value and not
necessarily the value in the file. Look at the code behind file for
the settings. As you add settings, it inserts new properties to the
Settings class so you can declare an instance of this class and use it
for your settings. One benefit is that you don't specify your setting
using a string literal like "FOO" so you reduce the chance for a typo.

What we have done is something like this:

using App.UI.Properties;

Settings _settings = new Settings();
string value = _settings.FOO;

I'm not 100% sure this is necessary, but it works.

>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(Assembl y.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


Oct 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
5
by: Paul Daly (MCP) | last post by:
I've created a windows forms appliation that gets its data from a sql database. I want to create an app.config file for this application so that in the event that the server name changes, they...
2
by: Chinmoy Mukherjee | last post by:
Hi All, I have a config file as followings IP_ADDR=1.2.3.4 PORT=1290 IP_ADDR=1.2.3.5 PORT=1291
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
8
by: vadim | last post by:
Hi, Is there a .Net control available that allows to write into web.config file appsettings section? The idea is to create encrypted user name and password for database connection and then...
3
by: Richard Lewis Haggard | last post by:
I have a test application that is calling an assembly that reads some strings out of a config file. Normally, this assembly supports a web application and the information can be read just fine....
17
by: Fred Nelson | last post by:
Hi: I have written several web applications that obtain their connection strings from the web.config file. This is very easy to use and it makes it easy to move an app from development into...
5
by: mmcd79 | last post by:
I built a VB.net application that makes use of a machine level DB connection string setting, and a user level starting location setting. The machine level setting and the default user based...
21
by: Nick Craig-Wood | last post by:
Lance Gamet <lance@gamet.comwrote: I've found http://docs.python.org/lib/module-ConfigParser.html To be easy to use and built in. It makes human readable / editable ..ini - like files. ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.