Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help accessing application settings using ConfigurationManager

Tags:

c#

.net

.net-2.0

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?

like image 900
Aaron Sanders Avatar asked Aug 28 '08 07:08

Aaron Sanders


2 Answers

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.

like image 134
Sergio Acosta Avatar answered Oct 04 '22 02:10

Sergio Acosta


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

like image 26
Joda Avatar answered Oct 04 '22 01:10

Joda