Zac*_*cci 6 c# configuration configurationmanager .net-core-3.0
我在应用程序调试/启动时收到以下错误:
System.TypeInitializationException: 'System.Data.Entity.Internal.AppConfig' 的类型初始值设定项引发异常。
FileNotFoundException:无法加载文件或程序集“System.Configuration.ConfigurationManager,Version=4.0.2.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”。该系统找不到指定的文件。
使用以下代码段DatabaeContext:
private CamelotViewsStandardContext db = new CamelotViewsStandardContext();
Run Code Online (Sandbox Code Playgroud)
该项目位于 .NET Core 3.0 上,并System.Configuration.ConfigurationManager安装了NuGet 包。它适用于 .NET Core 2.2 上的先前版本,所以不知道为什么它不适用于 3.0?
创建数据库上下文的参考背后的代码使用的是实体框架,应该在 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" />
Run Code Online (Sandbox Code Playgroud)
到.csproj项目的文件。
参考:https : //github.com/dotnet/runtime/issues/627