9

Please I updated my .NET 5 to .NET 6 and I have this errors on adding migration:

System.MissingMethodException: Method not found: 'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.
   at Abp.EntityFrameworkCore.AbpDbContext.OnModelCreating(ModelBuilder modelBuilder)
   at Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext`3.OnModelCreating(ModelBuilder modelBuilder)
   at Abp.Zero.EntityFrameworkCore.AbpZeroDbContext`4.OnModelCreating(ModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__8_4(IServiceProvider p)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCacMicrosoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'.

I have checked all my Microsoft.EntityFrameworkCore packages and they are of the same version. Is pointing this version of my code,

 protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<BinaryObject>(b =>
            {
                b.HasIndex(e => new { e.TenantId });
            });

            modelBuilder.Entity<ChatMessage>(b =>
            {
                b.HasIndex(e => new { e.TenantId, e.UserId, e.ReadState });
                b.HasIndex(e => new { e.TenantId, e.TargetUserId, e.ReadState });
                b.HasIndex(e => new { e.TargetTenantId, e.TargetUserId, e.ReadState });
                b.HasIndex(e => new { e.TargetTenantId, e.UserId, e.ReadState });
            });

            modelBuilder.Entity<Friendship>(b =>
            {
                b.HasIndex(e => new { e.TenantId, e.UserId });
                b.HasIndex(e => new { e.TenantId, e.FriendUserId });
                b.HasIndex(e => new { e.FriendTenantId, e.UserId });
                b.HasIndex(e => new { e.FriendTenantId, e.FriendUserId });
            });

            modelBuilder.Entity<Tenant>(b =>
            {
                b.HasIndex(e => new { e.SubscriptionEndDateUtc });
                b.HasIndex(e => new { e.CreationTime });
            });

            modelBuilder.Entity<SubscriptionPayment>(b =>
            {
                b.HasIndex(e => new { e.Status, e.CreationTime });
                b.HasIndex(e => new { PaymentId = e.ExternalPaymentId, e.Gateway });
            });

            modelBuilder.Entity<SubscriptionPaymentExtensionData>(b =>
            {
                b.HasQueryFilter(m => !m.IsDeleted)
                    .HasIndex(e => new { e.SubscriptionPaymentId, e.Key, e.IsDeleted })
                    .IsUnique();
            });

            modelBuilder.Entity<UserDelegation>(b =>
            {
                b.HasIndex(e => new { e.TenantId, e.SourceUserId });
                b.HasIndex(e => new { e.TenantId, e.TargetUserId });
            });

            modelBuilder.ConfigurePersistedGrantEntity();
        }

Is there thing I can implement to solve this issue.

2 Answers 2

19

This error occurs when you have different versions of Entity Framework Core and .NET Core in your project, please be sure to install the version of Entity Framework compatible with your .NET Core version.

For .NET 5.0 the packages are:

Microsoft.EntityFrameworkCore.Design [5.0.10]
Microsoft.EntityFrameworkCore.SqlServer [5.0.10]
Microsoft.EntityFrameworkCore.Tools [5.0.10]

For .NET 6.0 you can install:

Microsoft.EntityFrameworkCore.Design [6.0.10]
Microsoft.EntityFrameworkCore.SqlServer [6.0.10]
Microsoft.EntityFrameworkCore.Tools [6.0.10]

Sign up to request clarification or add additional context in comments.

3 Comments

I'm upgrading from 6.0 to 7.0 and ran into this issue. Make sure in addition to this you also upgrade the EFCore.NamingConventions package if you're using it :)
Also got this error when I forgot to update Z.EntityFramework.Plus.EFCore when I went from 6 to 7.
OK. Well, I'm in the situation where I'm having to maintian cross-project integration tests which are failing as only half the company has had time to upgrade to .NET 8. The tests are now disabled, which is seems as a high-risk/high-impact liability. So how would one use EFCore N-1 for one half (arrangement) of the integration test and EFCore N for the other (assert) half?
2

If you have only updated your EntityFrameworkCore nuget versions, you may encounter such an error.

Some of your nuget packages may have an old EntityFrameworkCore version.

Make sure that all your nuget packages are up to date.

For example, I upgraded my project and EntityFrameworkCore versions to version 8. The EntityFrameworkCore.EncryptColumn package was out of date and I was encountering this error. I got rid of this error with the preview version of the package.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.