我在应用程序调试/启动时收到以下错误:
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/