ConfigurationManager.AppSettings["NAME"] returns null

S

sandy.82in

Hi

I'm new to C# , I'm using VS2005 and .NET2.0 .Here is my
issue i just developed a simple application with app.config , and a
simple class library and following is my app.configfile

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Setting1" value="Very" />
<add key="Setting2" value="Easy" />
</appSettings>
</configuration>

and class library to call my appsettings
public class Class1
{
public string ReturnMsg()
{
string value = "";
foreach (string key in
System.Configuration.ConfigurationManager.AppSettings)
{
value +=
System.Configuration.ConfigurationManager.AppSettings[key];

}
return value;
}
}

Now my issue i'm getting value as null , why is that am i missing
anything i'm trying this from past 2 days please cananyone help
me .Are there any setting changes that i have to make . I tried
without foreach statement even then no luck. can anyone please tell me
where i'm going wrong .
thanks in advance
 
J

John Vottero

AppSettings isn't a collection of strings. Try using the
AppSettings.AllKeys property like this:

foreach(string key in AppSettings.AllKeys)
 

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