6
votes

I get the following error upon application debug/launch:

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.

With the following piece of code that uses DatabaeContext:

private CamelotViewsStandardContext db = new CamelotViewsStandardContext();

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?

2
What version of the System.Configuration.ConfigurationManager NuGet package are you using?JonyVol
I was under the impression the whole configuration story had been completely rewritten in .NET Core - so I believe you're probably just using the "wrong" configuration system. Check out what .NET Core offers out of the box, and tap into that.marc_s
I too, have similar problem. I updated to 3.1 Core today and it started failing. It was fine in 2.xNelson Rodriguez

2 Answers

5
votes

This happened to me when I upgraded a project from .NET Core 2.2 to 3.1. Unit tests would pass but the exception would be thrown when the webapp was deployed. I resolved it by adding

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

to the .csproj file for the project.

Reference: https://github.com/dotnet/runtime/issues/627

2
votes

install this package in both project

Install-Package System.Configuration.ConfigurationManager -Version 4.7.0