'System.Configuration.ConfigurationSettings.AppSettings' is obsolete

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?


Solution 1:

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:

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:

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:

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