question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF Core 6 RC1 breaks extensions due to a change in a contract

See original GitHub issue

File a bug

After updating my project to EF Core 6 RC1, extensions installed with the project stopped working due to a contract change:

Before: https://github.com/dotnet/efcore/blob/v5.0.10/src/EFCore/Infrastructure/DbContextOptionsExtensionInfo.cs#L49

public abstract class DbContextOptionsExtensionInfo {
    ....
    public abstract long GetServiceProviderHashCode();
}

After: https://github.com/dotnet/efcore/blob/v6.0.0-rc.1.21452.10/src/EFCore/Infrastructure/DbContextOptionsExtensionInfo.cs#L49

public abstract class DbContextOptionsExtensionInfo {
    ....
    public abstract int GetServiceProviderHashCode();
}

GetServiceProviderHashCode has a new return type of int rather than long. This causes the following exception in production when loading an extension that was compiled against a previous EF Core version:

System.TypeLoadException: 'Method 'GetServiceProviderHashCode' in type 'ExtensionInfo' from assembly 'EntityFrameworkCore.Projectables, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fc5550082a9c642c' does not have an implementation.'

A simple reproduction using: EntityFrameworkCore.Projectables:

 var serviceProvider = new ServiceCollection()
    .AddDbContext<ApplicationDbContext>(options => {
        options
             .UseSqlite(dbConnection)
             .UseProjectables() // Include our custom extension
         })
    .BuildServiceProvider();

// Causes System.TypeLoadException when targeting EF Core 6 RC1. Runs fine when targeting EF Core 6 preview 7 or earlier (including EF Core 5 and 3.1)
var dbContext = serviceProvider.GetRequiredService<ApplicationDbContext>(); 

EF Core version: 6.0.0-rc.1.21451.13 Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 6.0 RC 1) Operating system: Windows IDE: (e.g. Visual Studio 2022 17.4)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
AndriySvyrydcommented, Sep 15, 2021

Would fix this breaking change while still allowing extension authors to give an implementation to ShouldUseSameServiceProvider. Providing a custom implementation only affects EF Core 6 and beyond. Not providing an implementation means that there is still the chance of hash collisions.

Yes, I understand that your proposal allows extensions to work with EF Core 6 without fixing the original issue. But this issue is hard to debug and workaround when it happens, so we decided to take a break and fix it for good this time.

Note that 3.1 and 5.0 will go out of support next year: Releases

1reaction
ajcvickerscommented, Sep 15, 2021

@koenbeuk It’s more involved than that. I already discussed with @AndriySvyryd whether there was a reasonable way to avoid this. He can explain more if you want to pursue this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking changes in EF Core 6.0
Complete list of breaking changes introduced in Entity Framework Core 6.0.
Read more >
Ef core 6 breaking changes. Replace this call in 'MyFunction (s
In an attempt to correct many perceived deficiencies in Entity Framework Core, Microsoft is introducing 40 breaking changes to EF Core 3. This...
Read more >
Breaking changes in EF Core 7.0 (EF7)
Complete list of breaking changes introduced in Entity Framework Core 7.0 (EF7)
Read more >
EF Core 2.1 RC 1 GroupBy still evaluates locally
In my case the grouping was evaluated client-side for this query: await context.MyCollection .GroupBy(x => x.Tag.Id) .
Read more >
My ASP.NET 5 migration to .NET 6
I spent the last few days migrating our ASP.NET REST services, MVC web applications and Blazor server apps to .NET 6.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found