Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我在跑步时会遇到错误;添加迁移初始值“创建”;在.NET中?_C#_.net_Entity Framework Core_Migration - Fatal编程技术网

C# 为什么我在跑步时会遇到错误;添加迁移初始值“创建”;在.NET中?

C# 为什么我在跑步时会遇到错误;添加迁移初始值“创建”;在.NET中?,c#,.net,entity-framework-core,migration,C#,.net,Entity Framework Core,Migration,我有一个用Asp.net MVC和.net core 3.1构建的应用程序。我已经创建了模型、数据库上下文类和控制器。当我尝试在package manager命令行中运行命令:Add Migration InitialCreate时,出现以下错误: System.Reflection.TargetInvocationException:调用的目标已引发异常。 --->System.TypeLoadException:无法从程序集“Microsoft.EntityFrameworkCore,Ver

我有一个用Asp.net MVC和.net core 3.1构建的应用程序。我已经创建了模型、数据库上下文类和控制器。当我尝试在package manager命令行中运行命令:Add Migration InitialCreate时,出现以下错误:

System.Reflection.TargetInvocationException:调用的目标已引发异常。 --->System.TypeLoadException:无法从程序集“Microsoft.EntityFrameworkCore,Version=5.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”加载类型“Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer”。 位于Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOperationReportHandler reportHandler,IDictionary参数) ---内部异常堆栈跟踪的结束--- 在System.RuntimeMethodHandle.InvokeMethod(对象目标、对象[]参数、签名符号、布尔构造函数、布尔WrapeExceptions) 在System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr、Binder Binder、Object[]参数、CultureInfo区域性) 位于System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr、Binder Binder、Object[]args、CultureInfo区域性) 在System.Activator.CreateInstance(类型类型、BindingFlags bindingAttr、Binder Binder、对象[]参数、CultureInfo区域性、对象[]ActivationAttribute) 位于System.Activator.CreateInstance(类型,对象[]args) 位于Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(字符串汇编、字符串startupAssembly、字符串projectDir、字符串dataDirectory、字符串根命名空间、字符串语言) 在Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()中 在Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute()中 在Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.c__DisplayClass0_0.b_0()中 在Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(字符串[]args) 位于Microsoft.EntityFrameworkCore.Tools.Program.Main(字符串[]args) 调用的目标已引发异常


我听说这可能与Microsoft.EntityFrameworkCore.Design包有关,它需要更新到3.0.0版。我只是想知道需要对哪个文件进行更改,以及需要添加哪些必要的代码。

对齐EntityFrameworkCore的Nuget软件包的版本号。 对于设计,您使用5.0.0(Ms.EntityFrameworkCore.Design),对于Sqlite,您使用3.1.10(Ms.EntityFrameworkCore.Sqlite),对于工具3.1.10,对于SqlServer,它又是5.0.0

  • 统一
  • 恢复包
  • 清理、构建解决方案/项目
  • 请使用v3.1.10(或可用的最新3.x)作为所有NuGet软件包,如我在评论中所述。
    这将解决您的问题

    我认为您应该将软件包升级到3.1.10而不是3.0。顺便说一句,这些错误大多发生在您已经在项目/nuget Dependencies中引用了.NET 5.0 dll时。这是版本问题。请阅读此文章。希望您在阅读本文后获得解决方案。我已在命令行中运行此命令-dotnet工具更新-全局dotnet ef-版本5.0.0-并将重试。现在我遇到以下错误:找不到方法:“System.Collections.Generic.IEnumerable”。您的DLL错误。请发布您的目标框架以及安装了哪些NuGet软件包