Johannes Maximilian
Johannes Maximilian

Reputation: 77

the name configurationmanager does not exist in the current context

I'm using Visual Studio Community for Mac (.NETCore.App(2.1.0), MacOS 10.14.5) and I'm trying to use the ConfigurationManager class (https://learn.microsoft.com/de-de/dotnet/api/system.configuration.configurationmanager?view=netframework-4.8).

But i get the Error Message:

the name ConfigurationManager does not exist in the current context

I already added

using System.Configuration

to my code and also added the System.Configuration.dll (had to download it manually, because the reference list was completely empty) to the references.

Thanks for your help in Advance.

using System;
using System.Configuration;

namespace program
{
  public static class test{
     public static string val(string name){
        return ConfigurationManager.ConnectionStrings[name].ConnectionString;
     }
  }
}

Upvotes: 3

Views: 1372

Answers (2)

Mohith Maratt
Mohith Maratt

Reputation: 301

For Visual Studio 2019, I faced the same issue and this is how I resolved it:

Right click on project and go to Manage NuGet Packages.

enter image description here

Search for System.Configuraion and install System.Configuration.ConfigurationManager

enter image description here

Now in your code, configuration manager will be recognized.

enter image description here

Upvotes: 0

Christos
Christos

Reputation: 53958

You should install System.Configuration.ConfigurationManager package. So please try to execute the following command:

Install-Package System.Configuration.ConfigurationManager

Correction

Since you are working on Mac, I don't know If you can run the above command. This definitely works inside Visual Studio / Windows. So please follow the instructions found here for adding a dependency to the package mentioned above.

Upvotes: 3

Related Questions