patterncsharpCritical
Reading settings from app.config or web.config in .NET
Viewed 0 times
netappreadingwebfromsettingsconfig
Problem
I'm working on a C# class library that needs to be able to read settings from the
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
What is the best way to do this?
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.What is the best way to do this?
Solution
You'll need to add a reference to
You should definitely be using the
System.Configuration in your project's references folder. You should definitely be using the
ConfigurationManager over the obsolete ConfigurationSettings.Context
Stack Overflow Q#1189364, score: 896
Revisions (0)
No revisions yet.