当我尝试使用 EF Core (7.0.0-rc.1.22426.7) 添加迁移时,控制台中出现以下错误:
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.
有人遇到过这种情况并知道该怎么办吗?迁移一直进行到今天,我认为我没有在我的代码库中添加非常奇特的东西。任何指向正确方向的指针都会有帮助,因为谷歌还没有真正澄清任何事情......
安装
Microsoft.EntityFrameworkCore.Design
解决了我的问题
我第一次尝试时也收到了该消息。 还有另一个警告“实体框架工具版本‘6.0.13’比运行时‘7.0.2’旧。更新工具以获取最新功能和错误修复。”
所以我将 Microsoft.EntityFrameworkCore.Tools 更新到 7.0.2,与 Microsoft.EntityFrameworkCore.SqlServer 相同并修复了它
我遇到了同样的问题,就我而言,已安装的 EF Core 包和 EF Core 工具的版本之间存在不匹配。
将 nuget 包升级到版本 7.0.20 解决了我的问题。