【问题标题】:Can not get a reference to ConfigurationManager无法获得对 ConfigurationManager 的引用
【发布时间】:2010-12-12 03:46:59
【问题描述】:

我根本无法让 Visual Studio 2005 找到 System.Configuration.ConfigurationManager 类。代码如下:

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

我绝对肯定确实在项目中引用了System.Configuration,而且它肯定在正确项目中。 DLL 版本为 2.0.0.0,运行时版本为 2.0.50727 - 与所有其他版本完全相同。我已经尝试删除引用并重新添加它。一件奇怪的事情是,当它显示在项目的 References '文件夹' 中时,它显示为 'System.configuration' - 带有小写的'c'。

Visual Studio 可以找到 System.Configuration.ConfigurationSettings 类,除了警告它已过时之外没有任何问题。该项目是一个 Web 项目,代码位于 WebControl 的代码隐藏中。

有什么想法吗?

【问题讨论】:

    标签: .net visual-studio-2005 configurationmanager


    【解决方案1】:

    参考中的小写“c”是正常的。你的代码对我来说很好。我想知道您向我们展示的 sn-p 之外是否存在问题。尝试通过调用来引用其配置来构建全新的解决方案。证明这是有效的。

    【讨论】:

    • 感谢您的建议。事实证明,.NET 运行时完全搞砸了,因为安装它的帐户没有足够的权限。使用“上帝”帐户完全重新安装解决了该问题。很奇怪。
    【解决方案2】:

    您是否添加了对系统程序集 System.Configuration.dll 的引用?

    IIRC AppSettings 在 BCL 核心库中,2.0 ConfigurationManager 在单独的程序集中。

    【讨论】:

    • 我遇到了完全相同的问题。 VS2005 似乎知道 System.Configuration 命名空间的事实让我大吃一惊。一旦我添加了对 System.Configuration.dll 的引用,那么 ConfigurationManager 就可用了。谢谢!
    猜你喜欢
    • 2011-06-22
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 2010-10-03
    • 1970-01-01
    • 2012-07-10
    相关资源
    最近更新 更多