473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 5707
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.