views:

649

answers:

2

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?

+1  A: 

Did you add a reference to the System Assembly System.Configuration.dll?

IIRC AppSettings is in the BCL core library, 2.0 ConfigurationManager is in separate assembly.

+1  A: 

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.

Michael Petrotta
Thanks for the suggestion. Turns out that the .NET runtime was all messed up because the account it was installed with did not have enough rights. A full re-install with a 'god' account fixed the problem. Very weird.
TallGuy