Aaron Sanders
Aaron Sanders

Reputation: 726

Help accessing application settings using ConfigurationManager

In .net frameworks 1.1, I use

System.Configuration.ConfigurationSettings.AppSettings["name"];

for application settings. But in .Net 2.0, it says ConfigurationSettings is obsolete and to use ConfigurationManager instead. So I swapped it out with this:

System.Configuration.ConfigurationManager.AppSettings["name"];

The problem is, ConfigurationManager was not found in the System.Configuration namespace. I've been banging my head against the wall trying to figure out what I'm doing wrong. Anybody got any ideas?

Upvotes: 6

Views: 2670

Answers (5)

Prabhu
Prabhu

Reputation:

System.Configuration us refer to System.configuration (not the small case for configuration, in .net 2.o it reefers to System.Configuration.dll.

Upvotes: 0

Rory MacLeod
Rory MacLeod

Reputation: 11170

Visual Studio doesn't make it obvious which assembly reference you need to add. One way to find out would be to look up ConfigurationManager in the MSDN Library. At the top of the "about ConfigurationManager class" page it tells you which assembly and DLL the class is in.

Upvotes: 0

Joda
Joda

Reputation: 12906

If you're just trying to get a value from the app.config file, you might want to use:

ConfigurationSettings.AppSettings["name"];

That works for me, anyways.

/Jonas

Upvotes: 1

Sergio Acosta
Sergio Acosta

Reputation: 11450

You have to reference the System.configuration assembly (note the lowercase)

I don't know why this assembly is not added by default to new projects on Visual Studio, but I find myself having the same problem every time I start a new project. I always forget to add the reference.

Upvotes: 9

FantaMango77
FantaMango77

Reputation: 2437

You are missing the reference to System.Configuration.

Upvotes: 0

Related Questions