“The name 'ConfigurationManager' does not exist in the current context”未在当前上下文中存在。
“The name 'ConfigurationManager' does not exist in the current context”未在当前上下文中存在。
我正在尝试从配置文件中访问connectionStrings
。代码是ASP.NET + C#。我已经添加了System.Configuration
进行参考,并且还在using
中提到。但仍然不接受程序集。
我正在使用VSTS 2008。有什么想法可能是原因?
另一个奇怪的事情是程序集名称显示为“System.configuration”,其中包含小写的“c”,这不是其他System程序集如此显示的方式。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; namespace Utility { public class CommonVariables { public static String ConnectionString { get { return ConfigurationManager.ConnectionStrings["EmployeeEntities"].ConnectionString; } } } }
配置:
admin 更改状态以发布 2023年5月20日
在您的项目中,右键单击“添加引用...”,在.NET选项卡中找到System.Configuration
组件名称并单击确定。
使用System.Configuration
告诉编译器/IntelliSense搜索该命名空间中使用的任何类。否则,每次都必须使用完整名称(System.Configuration.ConfigurationManager
)。但是,如果您不添加引用,该命名空间/类将无法找到任何地方。
请注意,DLL可以有任何名称空间,因此文件System.Configuration.dll
在理论上可以具有名称空间Some.Random.Name
。为了清晰/一致通常是相同的,但有例外。