EF Core新增迁移时无法加载程序集“System.ValueTuple”的错误

简介: EF Core使用迁移命令时,如: Add-Migration Init 有时会出现如下错误: System.IO.FileLoadException: Could not load file or assembly 'System.

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元素。。。

目录
相关文章
System.IO.FileNotFoundException:“未能加载文件或程序集“loginDAL”或它的某一个依赖项。系统找不到指定的文件。”
System.IO.FileNotFoundException:“未能加载文件或程序集“loginDAL”或它的某一个依赖项。系统找不到指定的文件。”
|
12月前
|
网络安全
SNETCracker.exe 2022/1/26 31:13:29----检查12.26.20.1:SSH登录发生异常!未能加载文件或程序集“ChilkatDotNet4.dll”或它的某一个依赖项
SNETCracker.exe 2022/1/26 31:13:29----检查12.26.20.1:SSH登录发生异常!未能加载文件或程序集“ChilkatDotNet4.dll”或它的某一个依赖项
360 0
|
开发框架 .NET
解决NET Core发布iis项目覆盖原有的项目时"另一个程序正在使用此文件,进程无法访问"
解决NET Core发布iis项目覆盖原有的项目时"另一个程序正在使用此文件,进程无法访问"
多model项目下,某个项目引用了公共lib下的service, 其他模块想不受影响的启动解决办法
多model项目下,某个项目引用了公共lib下的service, 其他模块想不受影响的启动解决办法
74 0
|
数据库
.NET的EF框架中:在应用程序配置文件中找不到名为“”的连接字符串问题
.NET的EF框架中:在应用程序配置文件中找不到名为“”的连接字符串问题
395 0
.NET的EF框架中:在应用程序配置文件中找不到名为“”的连接字符串问题
未能加载文件或程序集“System.Web.Http.WebHost, Version=4.0.0.0, ”或它的某一个依赖项。系统找不到指定的文件。
未能加载文件或程序集“System.Web.Http.WebHost, Version=4.0.0.0, ”或它的某一个依赖项。系统找不到指定的文件。
661 0
|
C#
DLL分两种?用C#加载,有的成功,有的失败
DLL分两种?用C#加载,有的成功,有的失败
125 0