Can not get a reference to ConfigurationManager

0 votes
asked Nov 2, 2009 by tallguy

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 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?

2 Answers

0 votes
answered Nov 2, 2009 by jnoss

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.

0 votes
answered Nov 2, 2009 by michael-petrotta

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.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter