Search code examples
asp.net-corevisual-studio-2019configurationmanagerasp.net-core-5.0system.configuration

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


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?


Solution

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