我将.net标准类库从Entity Framework Core 1.1升级到Entity Framework 2.0
我正在尝试在针对.net framework 4.6.1的实体框架核心类库上运行Add-Migration
Add-Migration MyMigration
但是我得到以下错误
System.IO.FileLoadException:无法加载文件或程序集“System.ValueTuple,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040) 文件名:' System.ValueTuple,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51' 在Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.SharedTableConvention.Apply(InternalModelBuilder modelBuilder) 在Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder) 在Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext上下文,IConventionSetBuilder conventionSetBuilder,IModelValidator验证器) 在System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func
2 valueFactory) 在Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel() 在Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() 在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.CallSiteVisitor
2.VisitCallSite(IServiceCallSite callSite,TArgument参数) 在Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite,ServiceProvider provider) 在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.CallSiteVisitor
2.VisitCallSite(IServiceCallSite callSite,TArgument参数) 在Microsoft.Extensions.DependencyInjection.ServiceProvider。<> c__DisplayClass22_0.b__0(ServiceProvider provider) 在Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider,Type serviceType) 在Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService [T](IServiceProvider提供程序) 在Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies() 在Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider() 在Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService [TService](IInfrastructure1 accessor) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func
1工厂) 在Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType) 在Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name,String outputDir,String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name,String outputDir,String contextType) 在Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase。<> c__DisplayClass3_0`1.b__0() 在Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
我将System.ValueTuple的nuget包添加到我的csproj但我仍然收到错误
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
答案 0 :(得分:18)
将AutoGenerateBindingRedirects
和GenerateBindingRedirectsOutputType
添加到您的类库csproj
e.g。
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
....
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
答案 1 :(得分:1)
我遇到了同样的问题,安装.NET 4.7.1框架后修复了它
答案 2 :(得分:0)
从以下可爱的错误开始,因为StructureMap无法实例化Entity Framework Core的dbContext:
尝试创建类型为[[NameOfController]]的控制器时发生错误。确保控制器具有无参数的公共构造函数。
要使它在.NET Framework 4.6.2中工作,我必须做的工作比这里提供的答案还要多:
安装nuget(来源:https://github.com/neuecc/MessagePack-CSharp/issues/46)
添加到包含存储库的.proj中(来源:https://stackoverflow.com/a/45978409/581414)
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
然后转到web.config(来源:各种信息)
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
...
</configuration>