我根本无法让 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 - 与所有其他版本完全相同。我尝试删除引用并重新添加它。一件奇怪的事情是,当它显示在项目的引用“文件夹”中时,它显示为“System.configuration” - 带有小写的“c”。
Visual Studio 可以找到 System.Configuration.ConfigurationSettings 类,除了它已过时的警告之外没有任何问题。该项目是一个 Web 项目,代码位于 WebControl 的代码隐藏中。
任何想法这里发生了什么?
最佳答案
您是否添加了对系统程序集 System.Configuration.dll 的引用?
IIRC AppSettings 在 BCL 核心库中,2.0 ConfigurationManager 在单独的程序集中。
关于.net - 无法获得对 ConfigurationManager 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1659061/