c# - .NET Core 应用程序中的 ConfigurationManager

标签 c# configuration configurationmanager .net-core-3.0

我在应用程序调试/启动时收到以下错误:

System.TypeInitializationException: 'The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.'

FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.



使用以下使用 DatabaeContext 的代码:
private CamelotViewsStandardContext db = new CamelotViewsStandardContext();

该项目位于 .NET Core 3.0 上,System.Configuration.ConfigurationManager已安装 NuGet 包。它适用于 .NET Core 2.2 上的先前版本,所以不知道为什么它不适用于 3.0?

创建数据库上下文的引用背后的代码使用的是 Entity Framework ,应该在 3.0 中支持?

最佳答案

当我将项目从 .NET Core 2.2 升级到 3.1 时,这发生在我身上。单元测试会通过,但在部署 webapp 时会抛出异常。我通过添加解决了它

<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.Management" Version="4.7.0" />

.csproj项目的文件。

引用:https://github.com/dotnet/runtime/issues/627

关于c# - .NET Core 应用程序中的 ConfigurationManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57324985/

相关文章:

c# - Visual Studio 2010 中的自定义调试输出

eclipse - 无法创建 JPA Facet : "project facet jpt.jpa could not be found"

c# - BotFramework 和 LUIS 的 JSON 序列化器错误

c# - 如何根据默认样式制作圆边按钮样式

angular - 在两个构建中拆分 Angular CLI 应用程序

ios - 如何配置自定义 UITableViewCell 一次?

c# - 如何更新自定义配置部分中的 .NET 配置?

.net - 使用ConfigurationManager.OpenMappedExeConfiguration时如何从定义为NameValueSectionHandler的ConfigSection中获取值

c# - 无法获取我的自定义配置部分

javascript - ASP.NET Web API Controller 更新行