'Fragment' does not have an implementation exception when trying to add migration with EF Core 7
Asked Answered
G

3

15

When I'm trying to add a migration using EF Core (7.0.0-rc.1.22426.7) I'm greeted with the following error in the console:

System.TypeLoadException: Method 'Fragment' in type 'Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper' from assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
   at Microsoft.EntityFrameworkCore.Design.DesignTimeServiceCollectionExtensions.<>c__DisplayClass0_0.<AddEntityFrameworkDesignTimeServices>b__0(ServiceCollectionMap services)
   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.TryAddProviderSpecificServices(Action`1 serviceMap)
   at Microsoft.EntityFrameworkCore.Design.DesignTimeServiceCollectionExtensions.AddEntityFrameworkDesignTimeServices(IServiceCollection services, IOperationReporter reporter, Func`1 applicationServiceProviderAccessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.CreateServiceCollection(DbContext context)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(DbContext context)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method 'Fragment' in type 'Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper' from assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.

Has anyone encountered this before and know what to do about it? Migrations worked up until today and I don't think I've been adding very exotic things to my code base. Any pointers in the right direction are helpful since Google didn't really clarify anything yet...

Gibran answered 28/10, 2022 at 10:47 Comment(2)
I've been using this version for the last weeks without any issues creating a new migration... And I haven't recently updated anything either so I'm baffled this error just pops up.Gibran
Did you also update Microsoft.EntityFrameworkCore.Design to v7? It says it is using Version=6.0.8.0Joachima
D
10

Installing Microsoft.EntityFrameworkCore.Design solved the problem for me

Dramatization answered 10/11, 2022 at 10:3 Comment(0)
S
8

First time I tried I received that message also. There was another warning "The Entity Framework tools version '6.0.13' is older than that of the runtime '7.0.2'. Update the tools for the latest features and bug fixes."

So I updated the Microsoft.EntityFrameworkCore.Tools to 7.0.2 to be the same as Microsoft.EntityFrameworkCore.SqlServer and that fixed it

Sheridansherie answered 12/1, 2023 at 12:56 Comment(1)
I had different versions of the Microsoft.EntityFrameworkCore.Design in my solution, the models and API where still using an older version, updated project by project (solution package manager was not willing to do this) and now it works.Heinrike
S
1

I had the same issue and in my case there was a mismatch between the versions of the installed EF Core packages and the EF Core tooling.

  • dotnet-ef (CLI Tools) had version = 7.0.20
  • nuget package Microsoft.EntityFrameworkCore.Design had version = 6.0.32

Upgrading the nuget package to version 7.0.20 solved my issue.

Scoles answered 11/7, 2024 at 13:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.