|
-
July 8th, 2008, 09:56 AM
#1
AppSettings returns null value
Hi, I have come across a rather strange problem, seems quite straightforward, but I can't figure out what is wrong here:
I have a C# program with an application configuration file (app.config added in Visual Studio 2005). The contents of app.config are:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="KeyName" value="KeyValue"/>
</appSettings >
</configuration>
Now when I try to read the values from my config file
string sTemplateFile = ConfigurationManager.AppSettings.Get("KeyName");
or
string sTemplateFile = ConfigurationManager.AppSettings["KeyName"];
it returns null value
I have created the config file using the VS template. I can see the config file in my debug folder also.
Can anyone shed some light what is going on?
Thanks
Last edited by sunsilk10; July 8th, 2008 at 09:58 AM.
-
July 8th, 2008, 11:36 AM
#2
Re: AppSettings returns null value
what does this return when you run it?
Code:
bool hasKeys = ConfigurationManager.AppSettings.HasKeys();
-
July 9th, 2008, 03:16 AM
#3
Re: AppSettings returns null value
hasKeys returns false.
I think I might know the cause of the problem.
I am creating a class, which will be added as a tool in another main application.
Now, when I debug my C# program. I am launching the main application which contains my tool. I guess it is looking for the app.Config in the main application rather than in my program.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|