System.Configuration.ConfigurationManager not available?
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?
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.
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:
- Add the reference to System.Configuration.dll to your project
- Save your files
- Save your Solution
- Close the instance of Visual Studio that is giving you a hard time
- 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.
urgh - PICNIC error. Added ref to the wrong project in the solution...