problem reading AppSettings key/value pairs

J

jason

i am coding a simple console application with Visual C# .NET in Visual
Studio .NET

my config file (myapp.exe.config) has the following appSettings
section:

<appSettings>
<add key="myKey" value="myValue" />
</appSettings>


my code (myapp.exe) uses the following to try to access those settings:

string sValue = ConfigurationSettings.AppSettings["myKey"];
Console.WriteLine(sValue);


the problem is that sValue remains null. it is not getting assigned the
appropriate value from the appSettings.

after reading other threads on this topic, i have confirmed that i am
using System.Configuration, as well as including RCDigest.exe.config as
an application configuration compontent for the solution.

any ideas what i might be doing wrong?
 
J

jason

ah, yes, sorry about that. the example is myapp.exe.config, the ACTUAL
program is called RCDigest. however the two match perfectly
(RCDigest.exe.config and RCDigest.exe)

anything other than the file naming that might be to blame?

thanks,

jason
 
J

jason

well that would explain the problem.

the config file was created in the root project directory (i didn't put
it there, but Visual Studio .NET did) ... however the program is being
run from the /bin/debug directory off of the root project directory.
and Visual Studio.NET didn't think to copy the config file to the debug
folder so that the debug executable could use it.

thanks so much for taking me through the steps, i copied the config
file to the debug folder and all is well.

jason
 
G

Guest

Hi jason,

Glad that it worked.

BTW, if you name the config file as app.config in the VS solution, it would
automatically be copied into the target folder (debug or any other folder)
when the solution is built.

HTH,
Rakesh Rajan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top