Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#Appsettings给出错误:名称';配置管理器&x27;在当前上下文中不存在_C#_.net_Configurationmanager - Fatal编程技术网

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,它允许我使用我缺少的
语句自动添加