ConfigurationManager的命名空间在哪里?

问题描述 投票:27回答:6

我有一个对System.Configuration的引用 - 并且发现ConfigurationSettings没问题 - 但找不到类型或名称空间'ConfigurationManager'!

我读过 - 看起来它应该属于与ConfigurationSettings类相同的命名空间。

编辑:请注意 - 我已经清楚地说我添加了对System.Configuration的引用。已有4条关于此的评论。

c# .net-3.5 reference configurationmanager system.configuration
6个回答
42
投票

ConfigurationManager是.Net 2.0之后的System.Configuration的一部分。添加对System.Configuration dll的引用。尝试使用System.Configuration.ConfigurationManager。


15
投票

您需要使用System Configuration命名空间,这必须以两种方式包含:

  1. 右键单击项目并选择添加引用,浏览“程序集”并勾选System.Configuration程序集。
  2. 在代码中包含命名空间: 使用System.Configuration;

5
投票

您需要添加System.Configuration程序集的引用。此命名空间分为几个程序集。


5
投票

您需要在项目的Reference文件夹下添加System.Configuration引用。仅在类中使用using语句添加system.configuration是不够的。


4
投票

我正在使用VisualStudio 2015,并且ConfigurationManager不再出现在System.Configuration名称空间中。

我只是想读取App.config文件...

然后我找到了解决方案:

得到:

string str = MyProjectNamespace.Properties.Settings.Default["MySettingName"].ToString();

组:

MyProjectNamespace.Properties.Settings.Default["MySettingName"]="myString";
MyProjectNamespace.Properties.Settings.Default.Save();

2
投票

我正在使用VS 2017,我添加了“使用System.Configuration”指令,并按照步骤向项目添加引用程序集但IDE仍然抱怨配置管理器不存在,事实证明它是由于安装了.net核心通过Nuget只需添加一个空容器。还需要安装包System.Configuration.Configurationmanager 4.5.0。启动工具 - > Nuget包管理器 - >包管理器控制台,然后键入“Install-Package System.Configuration.ConfigurationManager -Version 4.5.0”,这样就可以解决问题。请参阅VS2017中对象浏览器中的屏幕截图

© www.soinside.com 2019 - 2024. All rights reserved.