Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add System.Configuration.ConfigurationManager to .NET core application

I need this package to access settings in the Web.config:

Restoring packages for D:\ ... path ... \dozor-backend.csproj...
Package System.Configuration.ConfigurationManager 4.4.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package System.Configuration.ConfigurationManager 4.4.0 supports:
  - net461 (.NETFramework,Version=v4.6.1)
  - netstandard2.0 (.NETStandard,Version=v2.0)
Package restore failed. Rolling back package changes for 'dozor-backend'.
Time Elapsed: 00:00:01.0720066
========== Finished ==========

I've seen other people use this package in net core app, so what's the issue? How can I use it in .NET Core app?

like image 499
Tomáš Zato - Reinstate Monica Avatar asked Sep 28 '17 15:09

Tomáš Zato - Reinstate Monica


People also ask

Does ConfigurationManager work in .NET Core?

ConfigurationManager was added to support ASP.NET Core's new WebApplication model, used for simplifying the ASP.NET Core startup code.

How do I add a reference to System configuration ConfigurationManager?

Right click the project and choose add reference, browse "Assemblies" and tick the System. Configuration assembly.

What is ConfigurationManager configuration?

The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class, which is deprecated. For web applications, use the WebConfigurationManager class.

Is it possible to use System Configuration Manager with ASP NET Core?

As error said, you can use System.Configuration.ConfigurationManager only starting from .NETCoreApp 2.0. For the previous version, you only have new ASP.NET Core configuration mechanism provided by Configuration API.

How do I add configuration to a dotNET console application?

Settings files, such as appsettings.json New .NET console applications created using dotnet new or Visual Studio by default do not expose configuration capabilities. To add configuration in a new .NET console application, add a package reference to Microsoft.Extensions.Hosting. Modify the Program.cs file to match the following code:

What version of NET Core does the configurationmanager NuGet package work on?

The project is on the .NET Core 3.0 with System.Configuration.ConfigurationManager NuGet package installed. It works on the previous version which is on the .NET Core 2.2 so no idea why it is not working on 3.0? The code behind the reference for creating the database context is using Entity Framework, which is supposed to be supported in 3.0?

Is system configurationmanager part of NET Standard 2?

Just to be clear here: System.Configuration.ConfigurationManager is not part of .NETStandard2.0. It's a package you're referencing. That package has to provide different implementations since in some cases it's providing an implementation and in other cases it's forwarding to existing desktop types.


1 Answers

As error said, you can use System.Configuration.ConfigurationManager only starting from .NETCoreApp 2.0. For the previous version, you only have new ASP.NET Core configuration mechanism provided by Configuration API.

Regarding a provided link: reread it carefully, it doesn't say that ConfigurationManager` is available and works with the previous version of .NET Core.

like image 59
Set Avatar answered Sep 21 '22 15:09

Set