efcore: Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.

ef6 数据库迁移时,

protected override void OnModelCreating(ModelBuilder builder)
        {
            
            base.OnModelCreating(builder);
}       

报错

Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Note there’s a good chance you’re mixing versions of EF Core; check your csproj and make sure the same version for all EF-related packages.

@ajcvickers after hitting this locally, AFAICT it’s due to the ClrType property moving from the ITypeBase interface up to its ‘parent’ interface of IReadOnlyTypeBase as part of the changes in EF core 6.0?

5.0, present on ITypeBase https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.itypebase.clrtype?view=efcore-5.0#microsoft-entityframeworkcore-metadata-itypebase-clrtype

6.0, missing from ITypeBase https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.itypebase?view=efcore-6.0

6.0, present on IReadOnlyTypeBase https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.ireadonlytypebase.clrtype?view=efcore-6.0#microsoft-entityframeworkcore-metadata-ireadonlytypebase-clrtype

So anything that builds against pre-6.0 referencing the ClrType property (in my example, off of the objects returned from builder.Model.GetEntityTypes()) and runs against 6.0 or later is going to hit this, at least AFAICT?

I tried making a fairly minimal repro at https://github.com/jamesmanningrapidscale/clrtype-missing-repro which just has a net6 console app use a netcore 3.1 class lib with an EF context

C:\Dev\clrtype-missing-repro\clrtype-missing-repro » dotnet run Unhandled exception. System.MissingMethodException: Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.

Should I open a new issue or can this one be reopened? Or is this By Design and having different build and runtime EF versions like this isn’t supported?

Thank you!

@michaelroeth you library references EF Core 3.1!

@asiena I’ve copy-pasted your csproj and made a minimal EF Core application, and everything works fine. Can you please prepare a runnable project which shows the exception happening?