Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationSettings.AppSettings is obsolete, warning

var values = new NameValueCollection
{
    { "key", ConfigurationSettings.AppSettings["API-Key"].ToString() },
    { "image", Convert.ToBase64String(File.ReadAllBytes(photo.ToString())) }
};

What's the new way to use the app.config file?

like image 805
Sergio Tapia Avatar asked Aug 10 '10 16:08

Sergio Tapia


People also ask

Can I use ConfigurationManager in .NET core?

ConfigurationManager was added to support ASP.NET Core's new WebApplication model, used for simplifying the ASP.NET Core startup code.

What is System Configuration ConfigurationManager Appsettings?

GetSection(String) Method (System. Configuration) Retrieves a specified configuration section for the current application's default configuration.


1 Answers

The ConfigurationManager class in System.Configuration:

ConfigurationManager.AppSettings

ConfigurationManager.ConnectionStrings

So your code would change to:

var values = new NameValueCollection 
{ 
    { "key", ConfigurationManager.AppSettings["API-Key"] }, 
    { "image", Convert.ToBase64String(File.ReadAllBytes(photo.ToString())) } 
}; 

Make sure you add a reference to System.Configuration along with the using statement for System.Configuration.

like image 200
Kelsey Avatar answered Sep 27 '22 20:09

Kelsey