c#Appsettings给出错误:名称';配置管理器&x27;在当前上下文中不存在
在我的课程顶部,我有以下内容:c#Appsettings给出错误:名称';配置管理器&x27;在当前上下文中不存在,c#,.net,configurationmanager,C#,.net,Configurationmanager,在我的课程顶部,我有以下内容: using System.Configuration; 在我的代码中,我有以下内容: int CompanyID = Convert.ToInt32(ConfigurationManager.AppSettings["CompanyId"] .ToString()); 但是,我得到了以下错误: The name 'ConfigurationManager' does not exist in the current context 我
using System.Configuration;
在我的代码中,我有以下内容:
int CompanyID = Convert.ToInt32(ConfigurationManager.AppSettings["CompanyId"]
.ToString());
但是,我得到了以下错误:
The name 'ConfigurationManager' does not exist in the current context
我不确定我错过了什么 您需要在项目中添加对System.Configuration的引用。若要稍微扩展,您需要添加对
System.Configuration.dll的引用才能使其正常工作。这是一种误导,因为System.Configuration
命名空间也存在于基本System.dll
中,并包含一些使用较少的对象,如。因此,它似乎真的应该起作用,但事实并非如此。这确实令人困惑,而且目前是.NET框架中的一个迟钝问题
幸运的是,System.Configuration.dll
位于.NET基本框架中,因此您只需右键单击项目中的References
文件夹,单击addreference
,然后在.NET
选项卡下查找System.Configuration
,即可添加引用
导入到项目中后,不要忘记使用System.Configuration将添加到要在中使用ConfigurationManager
的代码文件顶部。您可能会自己找到答案。:)您好,我做了您提到的事情:右键单击项目中的References文件夹,单击AddReference,然后在.NET选项卡下查找System.Configuration。但我还是得到了同样的信息。我也做了同样的构建message@WebDev天哪,好消息。我忘了在使用System.Configuration时在顶部添加。我总是忘记这一点,因为我使用resharper,它允许我使用我缺少的
语句自动添加。