EF Core使用迁移命令时,如:

Add-Migration Init

有时会出现如下错误:

System.IO.FileLoadException: Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.SharedTableConvention.Apply(InternalModelBuilder modelBuilder) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder) at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)

at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass22_0.b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider() at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure1 accessor)

at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

此时即使你添加如下包的引用,报错信息仍然会如如上所示:

<PackageReference Include="System.ValueTuple" Version="4.4.0" />

解决方案

修改工程文件,添加AutoGenerateBindingRedirects、GenerateBindingRedirectsOutputType和即可解决问题,如下所示:

<PropertyGroup>

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>

</PropertyGroup>

如果还报错,请将以下配置放在工程文件的第一个PropertyGroup元素。。。

EF Core新增迁移时无法加载程序集“System.ValueTuple”的错误的更多相关文章

  1. IIS部署时未能加载程序集&quot;System.Web.Http.WebHost&quot;解决方法

    问题如下 服务器没有安装MVC,下载以下dll覆盖到bin目录下,即可免安装运行程序. 下载地址:https://pan.baidu.com/s/1mhCo5mS

  2. MVC中未能加载程序集System.Web.Http/System.Web.Http.WebHost

    ==================================== 需要检查项目的Microsoft.AspNet.WebApi版本是否最新,System.Web.Http 这个命名空间需要更新 ...

  3. [翻译 EF Core in Action 2.4] 加载相关数据

    Entity Framework Core in Action Entityframework Core in action是 Jon P smith 所著的关于Entityframework Cor ...

  4. .NET/MVC-发布到IIS6.1提示未能加载程序集System.Web.Http.WebHost

    http://www.bubuko.com/infodetail-1128065.html vs2013发布后,自己的用iis7.0可以发布这个网站,但是用服务器2008 IIS6.1发布这个网站一直 ...

  5. SharpSvn 调用在运行时提示加载程序集出错,或有依赖项

    策略后引用: SharpSvn, Version=1.8009.3299.43, Culture=neutral, PublicKeyToken=d729672594885a28日志: 尝试下载新的 ...

  6. 修复使用&lt;code&gt;XmlDocument&lt;/code&gt;加载含有DOCTYPE的Xml时,加载后增加“[]”字符的错误

    C# LINQ TO XML - Remove “[]” characters from the DTD header http://stackoverflow.com/questions/12358 ...

  7. asp.net 无法加载程序集***

    1.vs2008,asp.net出现无法加载程序集...错误信息.可以通过删除项目的dll文件,重新编译运行解决问题. 2.我在global文件中的applicaiton_start开启了一个线程,不 ...

  8. 深入理解 EF Core:EF Core 写入数据时发生了什么?

    阅读本文大概需要 14 分钟. 原文:https://bit.ly/2C67m1C 作者:Jon P Smith 翻译:王亮 声明:我翻译技术文章不是逐句翻译的,而是根据我自己的理解来表述的.其中可能 ...

  9. 基于spring的web项目启动时预加载数据到ServletContext

    1.要在web启动时预加载数据到ServletContext,实现方法有很多,一种比较简单的方案就是: 1)新建一个bean,定义其初始化方法: <bean id="beanId&qu ...

随机推荐

  1. Entity Framework 数据库初始化四种策略

    策略一:数据库不存在时重新创建数据库 Database.SetInitializer<testContext>(new CreateDatabaseIfNotExists<testC ...

  2. this web application instance has been stopped already解决办法

    重启tomcat的时候出错 Illegal access: this web application instance has been stopped already.  Could not loa ...

  3. 将assembly包添加到自己的maven仓库

    mvn install:install-file -DgroupId=com.asiainfo -DartifactId=spark-assembly -Dversion=1.2.0 -Dpackag ...

  4. Java面试题之九

    四十六.Math.round(11.5)等於多少? Math.round(-11.5)等於多少? 对于这个题,只要弄清楚Math提供的三个与取整相关的方法就OK了. 1.ceil,英文含义是天花板,该 ...

  5. javascript动画效果之缓冲动画(修改版)

    在编写多块同时触发运动的时候,发现一个BUG, timer = setInterval(show, 30);本来show是一个自定义函数,当设为timer = setInterval(show(one ...

  6. hdu5925 Coconuts

    比完看acdream说这题是签到题 怎么都不会写 我现在补完也觉得 这不是傻逼题么 我我这个这么快5题的人真的不应该啊 #include<bits/stdc++.h> using name ...

  7. vue element-ui 设置时间组件

    备注:设置开始时间小于结束时间 <!-- 开始时间 --> <div class="block"> <!-- <span class=" ...

  8. 学习任务,阅读一下Redis分布式锁的官方文档

    地址: https://redis.io/topics/distlock 这是一篇质疑RedLock的论文:https://martin.kleppmann.com/2016/02/08/how-to ...

  9. java代码块执行顺序

    父类 public class Father { public Father() { System.out.println("父类构造PUBLIC father"); } stat ...

  10. 怎么解决tomcat占用8080端口问题图文教程

     怎么解决tomcat占用8080端口问题 相信很多朋友都遇到过这样的问题吧,tomcat死机了,重启eclipse之后,发现 Several ports (8080, 8009) required ...