Search code examples
.netvisual-studio-2005configurationmanager

Can not get a reference to ConfigurationManager


I simply can not get Visual Studio 2005 to find the System.Configuration.ConfigurationManager class. Here is the code:

using System.Configuration;

...

x = ConfigurationSettings.AppSettings["MySetting"]
// The name 'ConfigurationManager' does not exist in the current context

x = System.Configuration.ConfigurationManager.AppSettings["MySetting"]
// The type or namespace name 'ConfigurationManager' does not exist in the
// namespace 'System.Configuration' (are you missing an assembly reference?)

I absolutely, positively do have a reference to System.Configuration in the project and it is definitely in the right project. The DLL is version 2.0.0.0 and the runtime version is 2.0.50727 - exactly the same as all the others. I have tried removing the reference and re-adding it. One strange thing is that when it is displayed in the References 'folder' of the project, it is displayed as 'System.configuration' - with a lower case 'c'.

Visual Studio can find the System.Configuration.ConfigurationSettings class with no problem other than the warning that it is obsolete. The project is a web project and the code is in the code-behind of a WebControl.

Any ideas what is going on here?


Solution

  • The lowercase "c" in the reference is normal. Your code works for me just fine. I wonder if there's a problem outside of the snippet you've shown us. Try building a brand-new solution with just a call to reference its configuration. Prove that that works.