简体   繁体   English

更新数据库失败-BadImageFormatException

[英]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. 我们有一个开发人员团队致力于Asp.Net MVC5解决方案,通常在进行git pull获取其他开发人员更改之后,我们需要使用任何新的数据库迁移(实体框架6.1.3)来更新本地数据库。添加。

We run update-database in the Package Manager Console to update the database. 我们在程序包管理器控制台中运行update-database以更新数据库。 This worked until we changed all the projects to compile x64 output. 这一直有效,直到我们更改了所有项目以编译x64输出为止。 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 . 当我运行Update-database I've cleaned down all bin and obj folders before recompiling (to ensure all output would be the same format x64). 在重新编译之前,我已经清理了所有bin和obj文件夹(以确保所有输出的x64格式相同)。

It looks like the problem may be that the migrate.exe is not compatible with x64. 看来问题可能出在于migration.exe与x64不兼容。 SO , Original MSDN article . 因此原始MSDN文章

However this post is for EF5. 但是,该帖子适用于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. 如果不是的话,这似乎很奇怪,就好像x64或EF不是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. 问题在于,无论实际的构建路径是什么,enable-migrations命令似乎都具有一个硬编码的路径,其中EF在/ bin / Debug下查找项目的已构建DLL。 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. 当您将项目更改为x64时,Visual Studio会悄悄将项目的生成路径更改为/ bin / x64 / Debug-而EF会一直在/ bin / Debug中查找。 That causes this vague System.BadImageFormatException 这导致这个模糊的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. 只需将Project的构建路径更改为/ bin / Debug,这是无害的,而且神奇的是,一切都按照预期的方式开始工作。

https://stackoverflow.com/a/23666717 https://stackoverflow.com/a/23666717

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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