目标框架为4.0时出现System.BadImageFormatException [英] System.BadImageFormatException when target framework is 4.0
问题描述
在将目标框架更改为.net Framework 4之后,我遇到了运行时异常:
类型为'System.BadImageFormatException'的第一次机会异常发生在
I have a run time exception after changing Target Framework to .net framework 4: A first chance exception of type 'System.BadImageFormatException' occurred in
使用目标框架3.5进行构建时,一切正常。
When building with target framework 3.5, everything works fine.
我要构建的平台是x86(我发现在x64晚上构建会导致问题)。
The platform i am building to is x86 (i found out that building to x64 night cause the problem).
可能是什么问题?
推荐答案
MSDN 列出了可能的原因,因此建议通过此方法作为检查清单:
MSDN lists possible reasons for this, so I'd suggest running through this as a checklist:
-
尝试加载非托管动态链接库或可执行文件(例如Windows系统DLL),就像加载它一样是.NET Framework程序集。
An attempt is made to load an unmanaged dynamic link library or executable (such as a Windows system DLL) as if it were a .NET Framework assembly.
DLL或可执行文件作为64位程序集加载,但是它包含32位功能或资源。例如,它依赖于COM互操作或在32位动态链接库中调用方法。
A DLL or executable is loaded as a 64-bit assembly, but it contains 32-bit features or resources. For example, it relies on COM interop or calls methods in a 32-bit dynamic link library.
这样做的目的是确保所有项目和依赖项都被编译为针对同一框架版本或先前版本;并且您的每个项目在兼容性方面都是兼容的;并且如果要动态加载库,请确保加载它们的属性(即不要尝试将本机库作为托管程序集加载。)
The idea is to make sure that all of your projects and dependencies are either compiled to target the same framework version, or a previous version; and that each of your projects are compatible in terms of bitiness; and if you're loading libraries dynamically, be sure to load them property (i.e. don't try to load native libraries as managed assemblies.)
也许添加了更多信息有关您项目的配置/依赖性的信息,将使我们更具决定性。
Perhaps adding some more information about the configuration / dependencies of your project(s) would allow us to be more decisive.
这篇关于目标框架为4.0时出现System.BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!