Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFCore 6 support (Method not found exception) #485

Closed
Webreaper opened this issue Mar 14, 2021 · 18 comments
Closed

EFCore 6 support (Method not found exception) #485

Webreaper opened this issue Mar 14, 2021 · 18 comments
Labels

Comments

@Webreaper
Copy link

Get the following exception with EFCore 6 preview 2. BulkExtensions works fine with EFCore 6 preview 1 (as far as I can see so far).

I know you haven't tested/updated for EFCore 5 yet, let alone 6, but just thought I'd ping this FYI. No urgency.

System.MissingMethodException: Method not found: 'Microsoft.EntityFrameworkCore.Metadata.IEntityType Microsoft.EntityFrameworkCore.ModelExtensions.FindEntityType(Microsoft.EntityFrameworkCore.Metadata.IModel, System.Type)'.
   at EFCore.BulkExtensions.TableInfo.LoadData[T](DbContext context, Type type, IList`1 entities, Boolean loadOnlyPKColumn)
   at EFCore.BulkExtensions.TableInfo.CreateInstance[T](DbContext context, IList`1 entities, OperationType operationType, BulkConfig bulkConfig)
   at EFCore.BulkExtensions.TableInfo.CreateInstance[T](DbContext context, Type type, IList`1 entities, OperationType operationType, BulkConfig bulkConfig)
   at EFCore.BulkExtensions.DbContextBulkTransaction.Execute[T](DbContext context, IList`1 entities, OperationType operationType, BulkConfig bulkConfig, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkExtensions.BulkInsert[T](DbContext context, IList`1 entities, BulkConfig bulkConfig, Action`1 progress)
@borisdj
Copy link
Owner

borisdj commented Mar 14, 2021

Actually I have made test with EF 5 and nugets update, just haven't published the new version yet.
Want to clean up some issues before changing Target to .NetStandard 2.1.
It will be updated soon.
As for the EF6, don't plan to make those changes before it is fully released.
Still thx for the info.
I'll reference it on #425 issue.

@jamesgurung
Copy link

Same issue here. Please consider fixing this before the EF Core 6 release, if possible. BulkExtensions is really useful, and we're trying to keep up with the EF Core 6 previews for some of the improved features/performance.

@borisdj
Copy link
Owner

borisdj commented Mar 25, 2021

I'll take a look after finishing migration to .Net 5.

@borisdj
Copy link
Owner

borisdj commented Apr 3, 2021

Lib is upgraded to v5.+ with support for .Net 5 for EF Core 5.
Target in v5 is .NetStandard 2.1.

And I've tested it with EF Core 6 prev.2 in Test project where it fails with this error.
However I haven't found a solution to that.

Also I even tried updating nugets, in the library project itself, to this prerelease version just for test but wasn't able to install nugets, returns error:

Package Microsoft.EntityFrameworkCore 6.0.0-preview.1.21102.2 is not compatible with netstandard2.1, supports: net5.0

@ErikEJ
Copy link

ErikEJ commented Apr 3, 2021

@borisdj you need the latest VS preview!

@jamesgurung
Copy link

It looks like at the time of EF Core 6 Preview 2, the ModelExtensions class was mostly empty. That's why we're getting "Method not found".

In the latest code, the class has some methods back. FindEntityType is there, but it has a different signature (returning IReadOnlyEntityType?) so we'll likely still run into issues even when the next preview comes out.

The method is marked obsolete, and the recommendation is to use IReadOnlyModel.FindEntityType(Type type). This did not exist at all in EF Core 5, so there's no obvious fix that will be compatible with both current and preview versions.

EF Core 6 now targets .NET 5 rather than .NET Standard, which is explained in this blog post. Perhaps the best option would be a multitargeting approach?

@Webreaper
Copy link
Author

Any news on EFCore 6 support yet? It's only a couple of months until it'll be fully released. :)

@borisdj
Copy link
Owner

borisdj commented Sep 1, 2021

Doubt I'll have the time to work on this while in preview.
Probably will implement it in November after full release.

@borisdj borisdj changed the title Method not found exception with EFCore 6 preview 2 EFCore 6 support (Method not found exception) Sep 14, 2021
@Tealons
Copy link

Tealons commented Oct 1, 2021

Same here, we are making ready for .NET 6 upgrade and this package is blocking. Appreciate the effort and we will wait patiently.

@derigel23
Copy link

@borisdj EF Core 60 is already RC1. I'm pretty sure - no API changes will be in the release.
So if you start migrate it now - with it's official release you'll need to update only library version in dependencies.

@borisdj
Copy link
Owner

borisdj commented Oct 5, 2021

I'll take a look at it next week with RC2.

@borisdj
Copy link
Owner

borisdj commented Oct 6, 2021

Have managed to make v6
NuGet 6.0.0-rc.1 released.

@Webreaper
Copy link
Author

Very quick test - appears to work. Thanks for this!!

@borisdj
Copy link
Owner

borisdj commented Nov 10, 2021

.Net 6 fully released.

@borisdj borisdj closed this as completed Nov 10, 2021
@wdnijdam
Copy link

wdnijdam commented Nov 27, 2021

It is broken on net 6.0.0

Still having
----> System.MissingMethodException : Method not found: 'Microsoft.EntityFrameworkCore.Metadata.IEntityType Microsoft.EntityFrameworkCore.ModelExtensions.FindEntityType(Microsoft.EntityFrameworkCore.Metadata.IModel, System.Type)'.

Using ALL EF packages set to 6.0.0 while the library using it was built on 5.0.13.

@Webreaper
Copy link
Author

Webreaper commented Nov 27, 2021

I'm using dotnet 6, EFCore 6, and bulk extensions, and it all works just fine.

When you say "the library" was built on 5, which library?

@wdnijdam
Copy link

I created a NuGet package based on net 5.0.13 using EF core 5.0.12. I used the package from an net6.0 project. In the net6 project I forced the EF core version to 6.0.0. Then I receive the Method not found exception.

I solved it now by adding a net6.0 target for my package based on ef core 6.0.0. When using that from the net6 project the error is not occuring.

I checked al namespaces and type names. There are no differences that can explain the Method not found. One possible cause may be a difference in nullability. The linker may see different types due to differences in nullability.

@tobysainsbury
Copy link

tobysainsbury commented Nov 1, 2023

It is broken on net 6.0.0

Still having ----> System.MissingMethodException : Method not found: 'Microsoft.EntityFrameworkCore.Metadata.IEntityType Microsoft.EntityFrameworkCore.ModelExtensions.FindEntityType(Microsoft.EntityFrameworkCore.Metadata.IModel, System.Type)'.

Using ALL EF packages set to 6.0.0 while the library using it was built on 5.0.13.

Not working for me in .NET 6.0 either - I get the same error. All EF packages are version 6.0.24.

Edit: Managed to resolve this. Turns out the issue was a nuget package that I was using - despite the package dependencies in Visual Studio telling me the version of EF this particular package was using was 6.0.24, it was actually using EF 2, and an extension method only available in EF 2 (IModel.FindEntityType()).

This package was one of my own, so I was able to open the code and investigate - would never have figured this out if I didn't have access to the source code. I upgraded the framework of the package from netcore2.2 to net6.0, upgraded EF from 2 to 6 and refactored the troublesome code by casting the instance of IModel to IReadOnlyModel, as is the equivalent extension method for .NET 6.0/7.0 (see here: https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.ireadonlymodel.findentitytype?view=efcore-7.0):

var readonlyModel = (IReadOnlyModel)_dbContext.Model;
var entityTypeConfig = readonlyModel.FindEntityType(typeof(TEntity));

Installed the new version of the package into my solution and the error disappeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants