Fixing Obsolete System.Configuration.ConfigurationSettings.AppSettings in C#

Okay this is a quick one. If you’re having “‘System.Configuration.ConfigurationSettings.AppSettings’ is obsolete: ‘This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings’” as error message when working with C#, then you have come to the right place for the fix. Here we go then.

To fix it, just add a reference to “System.Configuration.dll“. And change from “ConfigurationSettings.AppSettings” to “ConfigurationManager.AppSettings“. (C# code example below)

Now if you have no idea what this gibberish above means, here is an in detail explanation. Non-noobs, please read no more. Noobs, follow the steps.

  1. Right-click on your project, look for Add Reference and click on it
  2. Choose the .Net tab and search for System.Configuration on the list
  3. Click on OK
  4. Now that the reference is added, just replace ConfigurationSettings.AppSettings with ConfigurationManager.AppSettings in your code. (C# code example below)

So if your code was like:

Console.WriteLine(ConfigurationSettings.AppSettings.Get("anyKey"));

It should now be like:

Console.WriteLine(ConfigurationManager.AppSettings.Get("anyKey"));

Now that this is fixed, you can get back to work on your project. It is an easy fix as you can see, but it’s not intuitive. I had to find the fix on aspcode.net. Hope this helps some of you out.

22 thoughts on “Fixing Obsolete System.Configuration.ConfigurationSettings.AppSettings in C#”

  1. Hello, this is about the 5th website I have been to that has said the same thing and the problem still persists.

    Fucking Microsoft man, they’re fucked, why even change this shit….I so wanna quit being a programmer right now…

    I could have implemented my own now…all the time i’ve spent trying to figure this shit out that should be EASY…wtf man…

    Fuck…can you tell I’m pissed off?

  2. Yes I can tell you are pissed. πŸ˜‰

    I know what you are going through. I have had a lot of problems where people have suggested me the same fix over and over again.

    What I’d advise you is to create a new project, add the “System.Configuration” reference and try the sample code given in the post. If that works, you can start migrating your code to the fresh project.

    Hope this helps.

  3. Sorry about the rude unsavory comments on your blog πŸ™

    Thank you, your code did actually work (well it’s compiling at least), and is easier and to the point than any the other few blogs I was at. I had a follow up problem where it’s not reading the keys. I haven’t gone back to look at it yet though.

    Is it just me though? or does this just seem like a really stupid thing to change? What possible reason could Microsoft have for changing it? It’s not like the implementation is any better.

    I don’t see good things coming from Microsoft in the next 5.10 or so years, it’s gonna be change after unnecessary change due to their business model which will inevitably flounder…I guess that’s a different topic though.

    Thanks heaps for your help, and I will go back to look at my problem soon πŸ™‚

  4. lol….I’m back again. It refuses to work.

    System.Windows.Forms.MessageBox.Show(System.Configuration.ConfigurationManager.ConnectionStrings[1].ToString());

    Says: “Specify the connection string either in machine.config or web.config”

    System.Windows.Forms.MessageBox.Show(System.Configuration.ConfigurationManager.ConnectionStrings[0].ToString());

    Says: “data source=.\SQLEXPRESS;Integrated Security=SSPI;etc etc”

    So my project must think that it’s a website or something, but its a WPF application. Am I horribly confused? I want to retrieve the keys from app.config

    I’m so just thinking of doing my own, I’d have got that working in like 5 minutes! Frustration is starting to rise again!!! lol…

  5. I’m so sorry to leave so many posts on your blog πŸ™ I have solved the problem.

    Properties.Settings.Default.WhateverKeyNameIs

    I hope that helps someone and demonstrates what a noob I am πŸ™‚

    Thank you

  6. Hey it’s nice to hear that you have managed to solve your problem.

    I have not seen into why Microsoft decided to change this. I agree that its not very practical. I’ll have to read on that some time. And maybe do an article about my findings… πŸ˜‰

  7. Nacho Regal,

    Thanks for the solution! Saved me a great deal of time (even though I had spent a fair amount of time trying to figure this out).

    Dietrich

  8. I am trying to resolve the issue of System.Configuration!System.Configuration.ConfigurationManager.AppSettings[“DALAssembly”]
    in C#.

    I have:
    1. Added Reference of System.Configuration
    2. Added using System.Configuration

    but still getting error on
    1. System.Configuration!System.Configuration.ConfigurationManager.AppSettings[“DALAssembly”]
    OR
    2. ConfigurationManager.AppSettings[“DALAssembly”]

    Can Anyone please help in this regard.

  9. I had the same issue. Whenever I removed the System.Configuration reference I still could not add the call to the ConfigurationManager. This was on an upgraded project from vs2005 to vs2010, I’m not sure if that is a factor.

    Howeverm I solved the issue by simply removing the reference to System (System.DLL) and I was then able to reference the namespace correctly.

    Hope this helps!

  10. Thank you for the Noobie information (I didn’t know how to add a reference to a dll).
    I’ve been searching for quite awhile, and you’ve given me everything I needed.

Leave a Reply

Your email address will not be published. Required fields are marked *

captcha

Please enter the CAPTCHA text