Entity Framework Core Migrations – Assembly Version Mismatch

If you have switched your .NET Core project from xproj to csproj (MSBuild) and updated the nuget packages then you may run into an issue when executing some of the dotnet ef-commands.

In this article:

Entity Framework Core Migrations – Assembly Version Mismatch
Pawel Gerr is architect consultant at Thinktecture. He focuses on backends with .NET Core and knows Entity Framework inside out.
I got the following error after executing dotnet ef migrations list:
				
					Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

				
			

The problem is that some of my (3rd party) dependencies are using version 1.1.0 and the others version 1.1.1. In a classic .NET 4.6 project we use assembly redirects to solve this kind of problems and the in .NET Core we do the same …

Just create an app.config file with the following content:

				
					<?xml version="1.0" encoding="utf-8"?>

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.EntityFrameworkCore" culture="neutral" publicKeyToken="adb9793829ddae60" />
                <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />"
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.EntityFrameworkCore.Relational" culture="neutral" publicKeyToken="adb9793829ddae60" />
                <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />"
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" />
                <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />"
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>
				
			

If you still getting errors than make sure you have the following items in your csproj-file

				
					<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0">
        <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
				
			
Free
Newsletter

Current articles, screencasts and interviews by our experts

Don’t miss any content on Angular, .NET Core, Blazor, Azure, and Kubernetes and sign up for our free monthly dev newsletter.

Related Articles
.NET
Roslyn Source Generators: Logging – Part 11
In previous part we lerned how to pass parameters to a Source Generator. In this article we need this knowledge to pass futher parameters to implement logging.
29.08.2023
.NET
Roslyn Source Generators: Configuration – Part 10
In this article we will see how to pass configuration parameters to a Roslyn Source Generator to control the output or enable/disable features.
29.08.2023
.NET
Roslyn Source Generators: Reduction of Resource Consumption in IDEs – Part 9
In this article we will see how to reduce the resource consumption of a Source Generator when running inside an IDE by redirecting the code generation to RegisterImplementationSourceOutput.
29.08.2023