Russ Clark Russ Clark - 1 year ago 60
C# Question

Reading settings from app.config or web.config in .net

I'm working on a C# class library that needs to be able to read settings the

file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows Forms application).

I've found that


works, but that code has been marked as deprecated by Microsoft.

I've read that I should be using:


However, the
class doesn't seem to be available from a C# Class Library project.

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

Answer Source

You'll need to add a reference to System.Configuration in your project's references folder.

You should definitely be using the ConfigurationManager over the obsolete ConfigurationSettings.