5

Whenever I want to update my EFCore reference to version 3 via NuGet on my NetFramework 4.8 project I get this error.

I confirm that I have netcore 3.0 SDK installed on my machine.

Visual studio error

Could not install package 'Microsoft.EntityFrameworkCore 3.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.              
Mohsen
  • 427
  • 4
  • 20
  • 1
    .NET Framework and .NET Core are two different things. You need regular ol' Entity Framework. – Eraph Sep 30 '19 at 22:22
  • @Eraph Can I use efcore 3 on .net framework 4.8? My current code uses efcore 2.2 – Mohsen Sep 30 '19 at 22:28
  • 1
    No, EF Core targets .NET Standard 2.1 which is not (nor will ever be) compatible with .NET Framework 4.X. – DavidG Sep 30 '19 at 22:30

1 Answers1

6

This is a major breaking change in EF Core 3.0. But was fixed in EF Core 3.1.

Starting with 3.0, EF Core targets .NET Standard 2.1 and will run on all platforms that support this standard. This does not include .NET Framework.

Breaking changes included in EF Core 3.0

And here is the tracking issue with lots of background on this change: Target .NET Standard 2.1

And no future version of .NET Framework is planned to support .NET Standard 2.1. See eg:

Given many of the API additions in .NET Standard 2.1 require runtime changes in order to be meaningful, .NET Framework 4.8 will remain on .NET Standard 2.0 rather than implement .NET Standard 2.1. .NET Core 3.0 as well as upcoming versions of Xamarin, Mono, and Unity will be updated to implement .NET Standard 2.1.

Announcing .NET Standard 2.1.

So you must jump to EF Core 3.1 and at least .NET Framework. 4.7.2.

[UPDATE]

EF Core 3.1 reintroduces support for .NET Standard 2.0, rather than requiring .NET Standard 2.1 as was the case for EF Core 3.0. This means EF Core 3.1 will run on .NET Framework versions that support the standard.

And the .NET Framework 4.7.2 and higher fully support .NET Standard 2.0, and so EF Core 3.1 also. See here for the support matrix. https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-3-1-and-entity-framework-6-4/

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
  • You just saved me after a day and a half of searching! Was running into some issues using an ef library in a .net core library. HOWEVER, all I had to do was use ef core 2.6 in my .net 4.8 access library since ef core 3.1 wouldn't work – Godrules500 Apr 09 '20 at 15:06
  • See update. This answer is out-of-date. EF Core 3.1 should work. – David Browne - Microsoft Apr 09 '20 at 16:08
  • 1
    Hmmm, I tried using ef core 3.1 on my .net 4.8 library and it did not work. Do I need to change my .net 4.8 lib to a .net standard? – Godrules500 Apr 13 '20 at 15:55
  • 2
    I just tried it, and did get a binding error, but worked around it with the tip here: https://stackoverflow.com/questions/43995432/could-not-load-file-or-assembly-microsoft-extensions-dependencyinjection-abstrac – David Browne - Microsoft Apr 13 '20 at 16:13
  • For some reason when I go to ef core 3, I get "A second operation started on this context" error even though it works on ef core 2. Not sure why it's doing that – Godrules500 Apr 14 '20 at 12:39
  • 1
    You might have been getting client-side evaluation in EF Core 2. In any case the fix is the same. Ensure you are scoping DbContext appropriately, and not sharing between threads, and completely fetch each query result before starting a new query on the DbContext. – David Browne - Microsoft Apr 14 '20 at 15:33
  • 1
    Yeah, I think that's the issue. How does that work with await async though? Every call I am using is async await. And I am dependency injecting the context, which was added on the startup.cs. Thanks for taking the time to respond by the way!! – Godrules500 Apr 14 '20 at 19:49
  • You should probably start a new question. The DI should configure the DbContext as scoped, and ASP.NET takes care of the rest. – David Browne - Microsoft Apr 14 '20 at 20:08