'System.ValueTuple, Version=0.0.0.0 required for Add-Migration on .NET 4.6.1 Class Library

9

I upgraded a .net standard class library from Entity Framework Core 1.1 to Entity Framework 2.0

I am trying to run Add-Migration on an Entity Framework Core Class Library that targets .net framework 4.6.1

Add-Migration MyMigration

But I then get the following error

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)

I added the nuget package of System.ValueTuple to my csproj but I still get the error

 <PackageReference Include="System.ValueTuple" Version="4.4.0" />
entity-framework-core
asked on Stack Overflow Aug 31, 2017 by dfmetro

3 Answers

18

Add AutoGenerateBindingRedirects and GenerateBindingRedirectsOutputType to your class library csproj

e.g.

<PropertyGroup>
    <TargetFramework>net461</TargetFramework>

    ....

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
answered on Stack Overflow Aug 31, 2017 by devfric
1

I had the same problem, and it got fixed after installing .NET 4.7.1 framework

answered on Stack Overflow Apr 28, 2018 by Gokulnath
0

Starting with the following lovely error because StructureMap failed to instantiate the dbContext for Entity Framework Core:

An error occurred when trying to create a controller of type '[NameOfController]'. Make sure that the controller has a parameterless public constructor.

I had to do some more work than the answers supplied here to get it to work in .NET Framework 4.6.2:

Install nugets (source: https://github.com/neuecc/MessagePack-CSharp/issues/46)

  • System.Threading.Tasks.Extensions (I used latest v4.5.2)
  • System.ValueTuple (I used old 4.3.1)

Add to .proj that contained repositories (source: https://stackoverflow.com/a/45978409/581414)

<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>

And to web.config (sources: various)

<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>

answered on Stack Overflow May 16, 2019 by Ruskin • edited May 16, 2019 by Ruskin

User contributions licensed under CC BY-SA 3.0