473,395 Members | 1,931 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,395 software developers and data experts.

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 20829
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sara | last post by:
We have a Cobol stored procedures on DB2 OS/390. We are able to access the stored procedures from a distributed platform Windows 2000/ Linux / Unix using DB2 Connect. But it does not return column...
0
by: Atul | last post by:
I have a .Net Managed C++ wrapper control for a MFC control. When using the ..Net control in a Visual Studio 2005 Beta 2 C# project and running in Debug mode, I get a crash saying something like...
0
by: George Durzi | last post by:
cross posted in datagrid group. Inside <columns/> in my datagrid, I have the following template column <asp:templatecolumn HeaderText="To Be Completed By"> <itemtemplate> <asp:Label...
9
by: Thomas Mlynarczyk | last post by:
Hi, It seems to be a generally adopted convention to have a function return FALSE in case of an error. But if a function is supposed to return a boolean anyway, one cannot distinguish anymore...
1
by: Anup | last post by:
Hi Group, I have a datagrid with dropdown in my application. I want to fill the data in dropdown by an ArrayList for that I am using "e.Item.FindControl("DropdownId")" but this function is...
5
by: anupamjain | last post by:
Tired, Exhausted, searched the web, usenets,forums thorughly but still clueless. I guess it's time to post on the group : This is the issue I have been trying to resolve since today morning : ...
3
by: rrpbatni | last post by:
Hi, I have a doubt in C++ where my method setlocale which is passed with two parameters LC_ALL and data_file_locale string for Portuguese locale is failing and returning NULL… What might be the...
1
by: sbowman | last post by:
I have the following CASE statement in a view: (SELECT CASE WHEN ISNULL(.., NULL) = NULL THEN .(..) ELSE .(..) + ', ' + .. END) AS ContactNameAndTitle It works perfectly when...
2
by: aaronharwood | last post by:
I have read dozens of existing responses on threads, that span the last 5 years or so, concerning this problem and while there are many solutions that appear to work for others - none work for me. ...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.