System.Configuration.ConfigurationManager not available?


.Net Problem Overview

In a VS2005 C# project I have added a reference to System.configuration. In the object browser, I can see the System.Configuration.ConfigurationManager. In Intellisense System.Configuration only has the old ConfigurationSettings, and not ConfigurationManager.

My code System.Configuration.ConfigurationManager.AppSettings["MySetting"]

is highlighted as a syntax error and does not compile.

In a different project, the exact same setup works just fine... any clues as to what is going on?

.Net Solutions

Solution 1 - .Net

Although the using System.Configuration; command is automatically generated in the using section, for some reason the actual reference is not set.

Go into add reference, .Net tab, and choose System.Configuration.

ConfigurationManager will now be resolved.

If you go to the project where the exact same setup works just fine and look at the references, you will see a reference to System.Configuration.

Solution 2 - .Net

To answer the question (not that it hasn't been answered already 5+ times) is to add System.Configuration as a reference to your project.

However what I would really like to highlight is that on many occasion I have added the System.Configuration.dll to my project's references, but for whatever special reason sometimes ConfigurationManager still won't show up in intellisense even after adding the reference to System.Configuration. Even if I remove the reference and add it again.

The very simple solution to this problem is to:

  1. Add the reference to System.Configuration.dll to your project
  2. Save your files
  3. Save your Solution
  4. Close the instance of Visual Studio that is giving you a hard time
  5. Re-open your solution

This simple exercise will get Visual Studio to behave again and stop telling you that you did not add your reference to System.Configuration. This exercise usually helps me with all inexplicable Visual Studio behaviors.

I have had this happen to me in both VS2008 and VS2010 multiple times and it works every time.

Solution 3 - .Net

urgh - PICNIC error. Added ref to the wrong project in the solution...

Solution 4 - .Net

For anyone who switches back and forth between developing ASP.NET WebForms and WinForms, this tip may come in handy.

If you are developing in a C# WinForms project, you will find that attempting to use a ConfigurationManager to get at your app.config settings will result in the following error:

> The name 'ConfigurationManager' does not exist in the current context

Since this is included by default in ASP.NET projects, this may come as a surprise. Just simply right-click on the "References" node in your project and look on the ".NET" tab. Scroll down and you should find System.Configuration. Add this to your project and you should be up and running.

Adding a Reference to System.Configuration

Provided you have already added System.Configuration to the using section at the top of your code, you should now be able to use config settings (such as connection strings) with code such as the following:

con.ConnectionString = ConfigurationManager.ConnectionStrings[sConnection].ConnectionString;

Solution 5 - .Net

  1. Go to Manage NuGet Packages
  2. Browse System.Configuration
  3. Install the Package System.Configuration.ConfigurationManager. View

Solution 6 - .Net

From the MSDN documentation -

> To use the ConfigurationManager class, your project must reference the > System.Configuration assembly. By default, some project templates, > like Console Application, do not reference this assembly so you must > manually reference it.

Solution 7 - .Net

I think you need to implicitly refer to System.Configuration assembly.

Solution 8 - .Net

It's just a guess, but maybe you should check if your project is using at least .NET framework 2.0. ConfigurationManager class is availvable since .NET 2.0 as dfescribed here: link on msdn

Solution 9 - .Net

wow - this was a hard one for me to resolve; in the end, I found that my program would only compile if included the reference (as expected) and removed the "Imports System.Net" statement (as I did not expect) from my module.


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
QuestionkpollockView Question on Stackoverflow
Solution 1 - .NetLill LanseyView Answer on Stackoverflow
Solution 2 - .NetdyslexicanabokoView Answer on Stackoverflow
Solution 3 - .NetkpollockView Answer on Stackoverflow
Solution 4 - .NetArsalanView Answer on Stackoverflow
Solution 5 - .NetManeesh ChaudharyView Answer on Stackoverflow
Solution 6 - .NetiliketocodeView Answer on Stackoverflow
Solution 7 - .NetTheVillageIdiotView Answer on Stackoverflow
Solution 8 - .NetView Answer on Stackoverflow
Solution 9 - .NetRobView Answer on Stackoverflow