.net-coresystem.configuration

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;
     }
  }
}

Solution

  • 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.