gpt4 book ai didi

c# - 无法从程序集“Microsoft.EntityFrameworkCore”中加载 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer'类型,

转载 作者:行者123 更新时间:2023-12-03 13:44:27 30 4
gpt4 key购买 nike

我有一个使用EF Core的ASP.NET Core 3.1 Web API应用程序。这是ConfigureServices类的Startup方法中的我的配置:

services.AddDbContext<ApplicationContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("AppConn")));
上面的配置已测试并适用于SQL Server数据库。
然后,在成功安装它的软件包后,我切换到使用Sqlite。
services.AddDbContext<ApplicationContext>(options =>
options.UseSqlite("Data Source=sqlitedemo.db"));
但是当我尝试添加EF迁移时
add-migration initial -context ApplicationContext
我收到此错误:

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=5.0.0.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, Object[] 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.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.

最佳答案

请更新您的 Entity Framework 核心nuget程序包至3.1.10(或最新的5.0.0)。它将解决您的问题。

关于c# - 无法从程序集“Microsoft.EntityFrameworkCore”中加载 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer'类型,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65058500/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com