The name 'ConfigurationManager' does not exist in the current context
It's not only necessary to use the namespace System.Configuration
. You have also to add the reference to the assembly System.Configuration.dll
, by
- Right-click on the References / Dependencies
- Choose Add Reference
- Find and add
System.Configuration
.
This will work for sure.
Also for the NameValueCollection
you have to write:
using System.Collections.Specialized;
In your project, right-click, Add Reference..., in the .NET tab, find the System.Configuration
component name and click OK.
using System.Configuration
tells the compiler/IntelliSense to search in that namespace for any classes you use. Otherwise, you would have to use the full name (System.Configuration.ConfigurationManager
) every time. But if you don't add the reference, that namespace/class will not be found anywhere.
Note that a DLL can have any namespace, so the file System.Configuration.dll
could, in theory, have the namespace Some.Random.Name
. For clarity/consistency they're usually the same, but there are exceptions.
Ok.. it worked after restarting the VSTS. The link suggested the solution for the same problem. Wish i could have seen it before. :)
Adding the System.Configuration
as reference to all the projects will solve this.
Go to
Project
->Add Reference
In the box that appears, click the
All assemblies
list tab in the left hand list.In the central list, scroll to
System.Configuration
and make sure the box is checked.Click ok to apply, and you'll now be able to access the
ConfigurationManager
class.
Adding this answer, as none of the suggested solutions works for me.
- Right-click on references tab to add reference.
- Click on Assemblies tab
- Search for 'System.Configuration'
- Click OK.