I received this error in a .NET 5.0 project using Visual Studio 2019 (tried on Community/Student edition as well as Professional).

"The type name 'ConfigurationManager' could not be found in the namespace 'System.Configuration'. This type has been forwarded..."

Many of the answers I found said that you needed to add "using System.Configuration;" as well as add the assembly namespace as a reference through Project -> Add Reference. This answer did not work for me as there is no "References" folder or any option to "Add Reference" in the Project tab. There is also no "Assemblies" tab in the Reference Manager. Only "Projects," "Shared Projects," "COM," and "Browse."

How do I add System.Configuration as a reference so that I may use ConfigurationManager?

3

There are 3 best solutions below

0
On BEST ANSWER

System.Configuration.ConfigurationManager is not supported in .NET 5. See here for how you would migrate an app with a web.config file to the .NET Core pattern Migration Configuration

While it might be possible to use System.Configuration.Configuration manager in a .NET 5 application, it is a bad idea. The framework has integrated the new stuff with application startup and if you don't use it you are making yourself more work. The newer configuration patterns are easier to use and deploy into multiple environments. If you have an existing .NET classic app you want to port to .NET 5, follow that documentation from above. If this is a new application check out the Microsoft.Extensions.Configuration namespace.

2
On

Edit: Although this answer may get rid of the error, this is not the "correct" answer as .NET 5 does not support ConfigurationManager. The other answers explain it best.

In Visual Studio 2019, click the Tools tab at the top.

Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution...

Search "System.Configuration.ConfigurationManager".

Install that to your project and the error should be gone.

0
On

.NEt 5 dosent Use Old ConfigurationManager you need to read from json

    public IConfiguration Configuration { get; set; }
    public Startup(IHostingEnvironment environment) 
    {
      Configuration = new Configuration()
                          .AddJsonFile("config.json");
    }
    
    
    var options = ConfigurationBinder.Bind<AppSettings>(Configuration); 
    Console.WriteLine(options.SomeSetting);

For more info please refer GitHub.com/aspnet/Options/test/Microsoft.Extensions.Options.Test/OptionsTest.cs