Where is ConfigurationManager's namespace?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 10:50:05

ConfigurationManager is a part of the System.Configuration after .Net 2.0. Add a reference to the System.Configuration dll. Try using System.Configuration.ConfigurationManager.

You need to use the System Configuration namespace, this must be included in two ways:

  1. Right click the project and choose add reference, browse "Assemblies" and tick the System.Configuration assembly.

  2. Include the namespace in code:

    using System.Configuration;

You need to add a reference the System.Configuration assembly. This namespace was split across a few assemblies.

You will need to add the System.Configuration reference under the Reference folder in your project. Only adding the system.configuration with the using statement in your class is not enough.

I'm working in VisualStudio 2015, and ConfigurationManager is not present at System.Configuration namespace anymore.

I was just trying to read the App.config file...

Then I found a solution:

Get:

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

Set:

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

I am using VS 2017, I added 'using System.Configuration' directive and also follow the step to add a reference assembly to the project but IDE still complaint configuration manager does not exist, it turn out it is due to the .net core installed by Nuget just add a empty container. The package System.Configuration.Configurationmanager 4.5.0 need to be installed as well. Start Tools -> Nuget Package Manager -> Package Manager Console and type "Install-Package System.Configuration.ConfigurationManager -Version 4.5.0" and this resolve the problem. Refer below screenshot in Object Browser in VS2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!