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?
ConfigurationManager was added to support ASP.NET Core's new WebApplication model, used for simplifying the ASP.NET Core startup code.
The web. config file has also been replaced in ASP.NET Core. Configuration itself can now be configured, as part of the application startup procedure described in Startup.
Application configuration in ASP.NET Core is performed using one or more configuration providers. Configuration providers read configuration data from key-value pairs using a variety of configuration sources: Settings files, such as appsettings. json.
The appSettings element is primarily for custom app settings that are unique to your app, and have no . NET (or ASP.NET) equivalents, like a list of your clients' email addresses, or the tagline and copyright info for your cat blog.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With