dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.73k stars 3.17k forks source link

Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite not working with .NET6.0 application #28235

Closed jessecallahan closed 2 years ago

jessecallahan commented 2 years ago

Trying to update application .NET 6.0 while class library targets .NETstandard 2.0.

We are trying to update our application to .NET6.0.

We have a class library that is a dependency and it targets .NETstandard 2.0.

According to NuGet.org, Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite v.3.1.8 should support .NET6.0 (it's listed as additional computed target framework)

However at runtime we are getting the error:

System.TypeLoadException: 'Method 'GetServiceProviderHashCode' in type 'ExtensionInfo' from assembly 'Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'

Class Library: EF Core version: 3.1.8 Database provider: Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite Target framework: .NETstandard 2.0

Application: EF Core version: 6.0.0 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET6

Operating system: Windows 11 Pro IDE: Visual Studio 2022 17.2

ErikEJ commented 2 years ago

You should update to 6 for all, you cannot mix dependencies like that

roji commented 2 years ago

As @ErikEJ wrote, the problem is mixing two versions of EF Core in the same application (3.1.8 and 6.0.0). You can continue using EF Core 3.1.8 after upgrading to .NET 6.0, though.

jessecallahan commented 2 years ago

Hi,

Thanks for the response.

We have now changed our EF Core version in our application back to 3.1.8 and we are running into another error.

So are set up -

Class Library: EF Core version: 3.1.8 Database provider: Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite Target framework: .NETstandard 2.0

Application: EF Core version: 3.1.8 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET6

Operating system: Windows 11 Pro IDE: Visual Studio 2022 17.2

New Error:

The type initializer for 'Microsoft.EntityFrameworkCore.EnumerableMethods' threw an exception.

The only information I could really decipher for this fix was found here: https://docs.microsoft.com/en-us/answers/questions/622611/net-6-upgrade.html

Which essentially says, the ef core packages in all libraries need to be updated to the newest version, in this case, 6.0.

Am I understanding this right? The only way to fix this is to update our EF Core version in our application and class libraries is to 6.0? (Which unfortunately is a problem based on our client's constraints)

Thanks in advance for your help.

roji commented 2 years ago

This sounds like #24002 - try using 3.1.26 instead of 3.1.8.

jessecallahan commented 2 years ago

Hi, this looks like its working so far ... I'll let you know when I successfully upgrade the full solution so you can close the ticket. Thanks!

roji commented 2 years ago

Closing as the reported bug matches a known issue. But if you encounter other issues, don't hesitate to post back or file a new bug.