.net Bad Image Format 异常问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4335505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bad Image Format exception problem
提问by Shashank
Possible Duplicate:
BadImageFormatException during .Net assembly load issue
I am trying to run a exe file which loads a assembly and extracts its version. The file is working fine on win xp but while running it on win 7 it crashes giving the following exception.
我正在尝试运行一个加载程序集并提取其版本的 exe 文件。该文件在 win xp 上运行良好,但在 win 7 上运行时崩溃,出现以下异常。
Unhandled Exception: System.BadImageFormatException: Could not load file or asse
mbly 'some.dll' or one of its dependencies. An attempt was made to load a program with
an incorrect format.
File name: 'some.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boo
lean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence
assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at NxTools.InstallTools.Utils.MIPSettings.MIPEnvironmentSettings.Main(String[
] args)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].
Has anybody faced this problem? What could be the probable solution to this problem?
有没有人遇到过这个问题?这个问题的可能解决方案是什么?
回答by Sam Holder
This can have several causes, the most likely is that you are trying to load a 32bit managed dll on a 64 bit machine, or vice versa.
这可能有多种原因,最有可能的原因是您尝试在 64 位计算机上加载 32 位托管 dll,反之亦然。
It can also mean that a dll you are dynamically loading is not a native dll, or that the dll file is corrupted.
这也可能意味着您正在动态加载的 dll 不是本机 dll,或者 dll 文件已损坏。
It may mean that you have a dll which is using a higher version of the .Net framework than some other dll that is using it, if you rebuilt a particular component with a different version for example.
这可能意味着您的 dll 使用的 .Net 框架版本比其他使用它的 dll 版本更高,例如,如果您使用不同版本重建特定组件。
This questioncovers similar ground, as does this onewhich also suggests a way to force your 64bit app to run in 32bit mode so it can load the 32bit dependency.
回答by Tobias Schittkowski
Please check if you are running a 64bit Windows and the dll ist 32bit ONLY (sometimes special versions for 64bit Windows are available)
请检查您是否正在运行 64 位 Windows 并且 dll 仅 32 位(有时可以使用 64 位 Windows 的特殊版本)

