4

可能重复:
.Net 程序集加载问题期间出现 BadImageFormatException

我正在尝试运行一个加载程序集并提取其版本的 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].

有人遇到过这个问题吗?这个问题的可能解决方案是什么?

4

2 回答 2

15

这可能有多种原因,最有可能是您试图在 64 位机器上加载 32 位托管 dll,反之亦然。

这也可能意味着您正在动态加载的 dll 不是本机 dll,或者 dll 文件已损坏。

例如,如果您使用不同版本重建特定组件,这可能意味着您有一个使用更高版本的 .Net 框架的 dll,而不是使用它的其他 dll。

这个问题涵盖了类似的基础,这个问题也提出了一种强制您的 64 位应用程序在 32 位模式下运行的方法,以便它可以加载 32 位依赖项。

于 2010-12-02T13:33:18.447 回答
3

请检查您是否正在运行 64 位 Windows 和 dll 仅 32 位(有时提供 64 位 Windows 的特殊版本)

于 2010-12-02T13:32:39.943 回答