views:

1425

answers:

3

I'm working on a C# class library that needs to be able to read settings the web.config or app.config file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows Forms application).

I've found that ConfigurationSettings.AppSettings.Get("MySetting") works, but that code has been marked as deprecated by Microsoft.

I've read that I should be using: ConfigurationManager.AppSettings["MySetting"].
However, the System.Configuration.ConfigurationManager class doesn't seem to be available from a C# Class Library project.

Does anyone know what the best way to do this is?

+13  A: 

You'll need to add a reference to System.Configuration in your references folder. You should definitely be using the ConfigurationManager over the obsolete ConfigurationSettings.

womp
+1  A: 

You must add to the project a reference to the System.Configuration assembly.

Otávio Décio
+1  A: 

Right click on your class Library, and choose the "Add References" option from the Menu; and finally from the .NET tab, select System.Configuration. This would include System.Configuration dll into your project.

Shiva