'System.Configuration.ConfigurationSettings.AppSettings' is obsolete

C#Visual StudioClassClass Library

C# Problem Overview


I got the following warning

> 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: > '"This method is obsolete, it has been replaced by > System.Configuration!System.Configuration.ConfigurationManager.AppSettings"'

How do you fix it?

C# Solutions


Solution 1 - C#

Add a reference to the assembly System.Configuration.

Then at the top (assuming C#) using System.Configuration (Imports System.Configuration in VB.NET).

Use ConfigurationManager.AppSettings["MySetting"] to access the settings!

Solution 2 - C#

as its a warning i dont think it matters unless you have turned off a treat warnings as errors setting

add a reference to System.Configuration

all you have to do is to update to the latest code so where you used ConfigurationSettings.AppSettings[""] change to ConfigurationManager.AppSettings[""]

and this should work

Solution 3 - C#

Just in case someone else was looking for the Add Reference option to achieve the accepted answer in Visual Studio 2010. (I had to do this in updating a VB project).

In Visual Studio 2010:

  1. Click on Project > Add Reference.
  2. Click on the C# tab (even though mine was a pure VB project)
  3. Scroll down halfway to find System.Configuration (I had v4 since .NET Framework 4.0 was the chosen version)
  4. Click OK, then update the line of code as per the suggestion given.

From System.Configuration.ConfigurationSettings.AppSettings("name") to System.Configuration.ConfigurationManager.AppSettings

Without adding the reference IntelliSense won't suggest ConfigurationManager when you type it, and that's because it doesn't have a reference to be aware of where it is. Which is also why you will get errors when you updated the line of code according to their suggestion.

Solution 4 - C#

the System.configuration DLL exsit in c:\Windows\Microsoft.NET\Framework\v2.0.50727\

Solution 5 - C#

After adding the reference using System.Configuration; at the top of the class. Still the same warning remains.

In Code Behind:

Instead of ConfigurationSettings.AppSettings["ConnectionString"]

Use ConfigurationManager.AppSettings["ConnectionString"]

By Default the System.configuration Dll will be added in your project.

In Web.config or App.config:

 <add key="ConnectionString" value="Some Connection Strings or Specific Path"/>

Solution 6 - C#

to use ConfigurationManager.AppSettings[""] Add Reference Assemblies not use using System.Configuration;

Solution 7 - C#

Just replace
System.Configuration.ConfigurationSettings.AppSettings
with
System.Configuration!System.Configuration.ConfigurationManager.AppSettings
in your code.

Solution 8 - C#

you must add reference of System.onfiguration in your project then add "Using System.onfiguration;"

next step using like this:

private string SQLConnectionString = ConfigurationManager.AppSettings["SQlConnectionString"]; 

Solution 9 - C#

example:

replace

string smtpServer = System.Configuration.ConfigurationSettings.AppSettings["EmailServer"];

with

string smtpServer = ConfigurationManager.AppSettings["EmailServer"];

also make sure on the top of the case you add:

using System.Configuration;

Solution 10 - C#

It's simple as mentioned above, just add a reference "System.Configuration" for the application, and within the code you can add "using System.Configuration" to the top of the code and use "ConfigurationManager.AppSettings[""]" where you need it.

Solution 11 - C#

I also face same issue, sometimes the assembly reference not loaded properly or if you are using multiple projects it give problems sometimes. You just add reference to assembly. Right Click>Add Reference>.Net>System.configuration> Click OK You can see now there are many configuration options available choose ConfigurationManager.AppSetting["Con"].ToString();

Build and Smile :)

Solution 12 - C#

I had the same problem in a C# project and I fixed it by writing appSettings instead of AppSettings in the XML file (camelCase expected) in the tag

<appSettings>
  <add key="myKey" value="my Value"/>
<appSettings>

After all C# is case sensitive

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question001View Question on Stackoverflow
Solution 1 - C#Mike CheelView Answer on Stackoverflow
Solution 2 - C#stack72View Answer on Stackoverflow
Solution 3 - C#matrixanomalyView Answer on Stackoverflow
Solution 4 - C#Ziv.TiView Answer on Stackoverflow
Solution 5 - C#RajeshKdevView Answer on Stackoverflow
Solution 6 - C#ewwinkView Answer on Stackoverflow
Solution 7 - C#Mahesh PadekarView Answer on Stackoverflow
Solution 8 - C#Luay AlsalehView Answer on Stackoverflow
Solution 9 - C#azoteView Answer on Stackoverflow
Solution 10 - C#Mohammad EidView Answer on Stackoverflow
Solution 11 - C#AirCode OneView Answer on Stackoverflow
Solution 12 - C#Fred SmithView Answer on Stackoverflow