Assembly version mismatch exception when connecting to database with migrations from older version


Here is situation: I have DAL assembly that connects to DB using EntityFramework code fist. Recently we added strong names to our assemblies, including DAL. Now, when connecting to database, if last migration was on previous version of DAL (or different public token), I get exceptions like this one:

Could not load file or assembly 'MyProject.DAL, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Current version of DAL is Exception is database-specific, one of older databases was looking for If I create new blank migration on current version and apply it, exception stops, but if I change DAL version again, I get exception again. What causes this exception and how do I prevent it from happening on every DAL version update?

asked on Stack Overflow Aug 12, 2020 by Deo

1 Answer


Recently we added strong names to our assemblies, including DAL

For which of these reasons are you doing that?

When you change the public key token (by strong-naming) or increment the AssemblyVerion (not the AssemblyFileVersion) you are breaking backwards-compatibility.

After such a change you should probably just start over with a new initial migration.

You might be able to work around the AssemblyVersion difference with a Binding Redirect.

User contributions licensed under CC BY-SA 3.0