Add-Migration initDatabase报错

Build started...

Build succeeded.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

 ---> System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer' from assembly 'Microsoft.EntityFrameworkCore, Version=6.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

   at Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOperationReportHandler reportHandler, IDictionary args)

   --- End of inner exception stack trace ---

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)

   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)

   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)

   at System.Activator.CreateInstance(Type type, Object[] args)

   at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)

   at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()

   at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute()

   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0()

   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)

   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)

Exception has been thrown by the target of an invocation.

请先 登录 后评论

1 个回答

admin - DTcms技术经理

首先确保API项目编译通过,设置API项目为启动项目,在迁移面板中将当前项目设置为DB项目,再执行命令。

请先 登录 后评论
  • 1 关注
  • 0 收藏,1520 浏览
  • kenny880629 提出于 2023-01-12 10:28

相似问题