469,360 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

ConfigurationSettings.AppSettings["mySetting"] returning null

I have a C# console app, MyApp, and am placing an application config file in
the same debug dir as MyApp.exe. I have named the file MyApp.config, and
MyApp.exe.config. I cannot read the <appSettings> entries in the file
though, I get null back for properties.

config file
<configuration>
<appSettings>
<add key="mySetting" value="hello_world" />
....

Code is:
string test = ConfigurationSettings.AppSettings["hello_world"];

Any ideas? test winds up null. I'm going off...

http://www.codeguru.com/Csharp/Cshar...int.php/c7987/

Thanks in advance!

Derrick
Nov 16 '05 #1
5 20288
Was it just a typo or shouldn't it be ["mySetting"] not ["hello_world"]

Chris
"Derrick" <de*********@excite.com> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have a C# console app, MyApp, and am placing an application config file
in
the same debug dir as MyApp.exe. I have named the file MyApp.config, and
MyApp.exe.config. I cannot read the <appSettings> entries in the file
though, I get null back for properties.

config file
<configuration>
<appSettings>
<add key="mySetting" value="hello_world" />
...

Code is:
string test = ConfigurationSettings.AppSettings["hello_world"];

Any ideas? test winds up null. I'm going off...

http://www.codeguru.com/Csharp/Cshar...int.php/c7987/

Thanks in advance!

Derrick

Nov 16 '05 #2
How did you add the file to your project? Try doing the following:

Right-click on the project and follow the Add popup menu
Click on Add New Item
Under the Local Project Items node, select Utility
Select Application Configuration File and click OK. Leave the file's name
as App.config.

AFAIK, those are the steps you must take to add a config file. I believe
that if you manually add it, it will get deleted every time you build the
project.

- Jon
"Derrick" <de*********@excite.com> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have a C# console app, MyApp, and am placing an application config file
in
the same debug dir as MyApp.exe. I have named the file MyApp.config, and
MyApp.exe.config. I cannot read the <appSettings> entries in the file
though, I get null back for properties.

config file
<configuration>
<appSettings>
<add key="mySetting" value="hello_world" />
...

Code is:
string test = ConfigurationSettings.AppSettings["hello_world"];

Any ideas? test winds up null. I'm going off...

http://www.codeguru.com/Csharp/Cshar...int.php/c7987/

Thanks in advance!

Derrick

Nov 16 '05 #3
sorry, just a typo. I am using same code that I use in an ASP.NET web that
does work. only difference is that in the web the config is called
Web.Config

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Was it just a typo or shouldn't it be ["mySetting"] not ["hello_world"]

Chris
"Derrick" <de*********@excite.com> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have a C# console app, MyApp, and am placing an application config file
in
the same debug dir as MyApp.exe. I have named the file MyApp.config, and MyApp.exe.config. I cannot read the <appSettings> entries in the file
though, I get null back for properties.

config file
<configuration>
<appSettings>
<add key="mySetting" value="hello_world" />
...

Code is:
string test = ConfigurationSettings.AppSettings["hello_world"];

Any ideas? test winds up null. I'm going off...

http://www.codeguru.com/Csharp/Cshar...int.php/c7987/
Thanks in advance!

Derrick


Nov 16 '05 #4
That was it! Thanks!!!

Derrick

"Jon Sagara" <jo*******@yahoo.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
How did you add the file to your project? Try doing the following:

Right-click on the project and follow the Add popup menu
Click on Add New Item
Under the Local Project Items node, select Utility
Select Application Configuration File and click OK. Leave the file's name
as App.config.

AFAIK, those are the steps you must take to add a config file. I believe
that if you manually add it, it will get deleted every time you build the
project.

- Jon
"Derrick" <de*********@excite.com> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
I have a C# console app, MyApp, and am placing an application config file
in
the same debug dir as MyApp.exe. I have named the file MyApp.config, and MyApp.exe.config. I cannot read the <appSettings> entries in the file
though, I get null back for properties.

config file
<configuration>
<appSettings>
<add key="mySetting" value="hello_world" />
...

Code is:
string test = ConfigurationSettings.AppSettings["hello_world"];

Any ideas? test winds up null. I'm going off...

http://www.codeguru.com/Csharp/Cshar...int.php/c7987/
Thanks in advance!

Derrick


Nov 16 '05 #5
You have mixed up the key and the value. 'mySetting' is the key and
'hello_world' is the value.

Your code should read:
string test = ConfigurationSettings.AppSettings["mySetting"];

Regards,
Joakim

Derrick wrote:
I have a C# console app, MyApp, and am placing an application config file in
the same debug dir as MyApp.exe. I have named the file MyApp.config, and
MyApp.exe.config. I cannot read the <appSettings> entries in the file
though, I get null back for properties.

config file
<configuration>
<appSettings>
<add key="mySetting" value="hello_world" />
...

Code is:
string test = ConfigurationSettings.AppSettings["hello_world"];

Any ideas? test winds up null. I'm going off...

http://www.codeguru.com/Csharp/Cshar...int.php/c7987/

Thanks in advance!

Derrick

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sara | last post: by
reply views Thread by George Durzi | last post: by
9 posts views Thread by Thomas Mlynarczyk | last post: by
1 post views Thread by sbowman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.