Search code examples
c#.net-coreentity-framework-5.net-framework-version.net-standard-2.0

Mixing .NET Core and Framework in same solution - System.Data.Entity Issue


I am giving our legacy .NET 4 Framework libraries a new entry via .NET Core WebAPIs. Unfortunately, I am stuck at an issue at runtime (while loading dependency container) in the webapi project (net core):

FileNotFoundException: Could not load file or assembly 'System.Data.Entity'

I tried explicitly adding reference to Entity in webapi project but then I get BadImageReferenceException, I am aware this library is discontinued in net core.

The Legacy .NET 4 Framework library has extensive use of EntityFramework (5.0.0) so System.Data.Entity is heavily used. I tried to port these libraries to .netstandard but a lot of code change is required.

Any options I have to avoid (heavy) code change where I can use the shiny new api in core and supporting libraries untouched?


Solution

  • EF5 is not compatible with .Net Core. The only classic EF version that runs on .Net Core is Entity Framework 6 since Version 6.3:

    • Support for .NET Core 3.0
      The EntityFramework package now targets .NET Standard 2.1 in addition to .NET Framework 4.x.

    So update from EF5 to EF6 to fix your issues.