简体   繁体   中英

Update-database failing - BadImageFormatException

We have a team of developers working on an Asp.Net MVC5 solution, and often after doing a git pull to get the other developers changes we need to update our local databases with any new Database Migrations (entity framework 6.1.3) which have been added.

We run update-database in the Package Manager Console to update the database. This worked until we changed all the projects to compile x64 output. Which was needed to resolve memory requirements.

However now I am getting :

System.BadImageFormatException: Could not load file or assembly 'My.Data' or one of its dependencies. 
    An attempt was made to load a program with an incorrect format.

When I run Update-database . I've cleaned down all bin and obj folders before recompiling (to ensure all output would be the same format x64).

It looks like the problem may be that the migrate.exe is not compatible with x64. SO , Original MSDN article .

However this post is for EF5. Is this still the case? And is there a workaround? if not it seems bizarre, its not as if x64 or EF are new additions to Visual studio.

Managed to find the answer.

The problem is that the enable-migrations command appears to have a hard-coded path where EF looks for built DLLs of your project at /bin/Debug, no matter what the actual build path is. When you change a Project to x64, Visual Studio quietly changes your project's build path to /bin/x64/Debug - while EF keeps looking in /bin/Debug. That causes this vague System.BadImageFormatException

It's harmless to just change your Project build path to /bin/Debug and magically, everything begins working like it's supposed to.

https://stackoverflow.com/a/23666717

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM