开发者

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 - ex开发者_如何转开发actly 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜