System.BadImageFormatException occurred when build in Release Mode

跟風遠走 提交于 2019-12-01 23:39:24

More than a Debug/Release mode I'll say it's a 32 vs 64 bits problem. Probably you have the Platform target for the Debug mode to Auto and for the Release mode to 32/64 bits and you are using a dll that is only 32 or 64 bits, so in Debug (Platform target Auto) mode the .NET can "select" between 32 and 64 bits to be compatible with the dll, while in Release (Platform target 32 or 64 bits) it can't.

(note that if you have multiple projects in the same solution you have to check all the projects properties for this! It's in the properties of each project, Build, Platform target)

I ran into this (or something similar) yesterday also. Both Debug and Release mode are set to AnyCPU but the exe is referencing a 32-bit dll. While debugging, the exe appears to default to 32-bit (I assume because Visual Studio is 32-bit) but when in release mode, it switches to 64-bit (I assume because my computer is 64-bit). So when I force it to always be 32-bit (x86), everything should and does work great! Hope this helped!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!