12

我正在尝试在 Win7 x64 上运行我的 .NET 3.5 WinForms 应用程序。该应用程序使用 NHibernate 和 System.Data.OracleClient 来访问 Oracle 数据库。Oracle 客户端是 32 位的。

启动应用程序时,我收到以下错误消息

尝试加载 Oracle 客户端库会引发 BadImageFormatException。在安装了 32 位 Oracle 客户端组件的 64 位模式下运行时会出现此问题。

作为回应,我将我的构建定位到 x86 平台:

构建设置的屏幕截图

令我惊讶的是,在 Win7 平台上尝试执行新版本时出现了同样的错误消息。

NHibernate 程序集在运行时由Assembly.Load("...");.

可能是 NHibernate DLL 仍然以 64 位模式运行,而主机 exe 以 32 位模式运行。这对我来说听起来很奇怪。或者可能是出于某种原因,我的应用程序在 64 位模式下运行,即使它是针对 x86 的?


更新:

我使用 CorFlags 检查了我的二进制文件,它被标记为 32 位:

Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Version   : v2.0.50727
CLR Header: 2.5
PE        : PE32
CorFlags  : 3
ILONLY    : 1
32BIT     : 1
Signed    : 0

我还在任务管理器中检查了它,它有一个*32后缀。

我还尝试并使用 CorFlags 将 32 位标志添加到我的应用程序附带的所有程序集中。它仍然会产生相同的错误消息。

我纳闷……纳闷……纳闷……

4

6 回答 6

6

32 位进程无法加载 64 位 DLL,反之亦然(有关详细信息,请参阅内容)。这意味着如果您的进程成功加载了 64 位 DLL,那么它肯定是 64 位进程。您可以在任务管理器中(如 Lasse 建议的那样)或通过此处描述的其他方式进行验证。该文章还提供了有关 Windows x64 上 .Net 的更多信息。

于 2011-06-30T10:42:55.757 回答
3

正确,听起来 NHibernate 程序集是AnyCPU作为其平台目标构建的。您需要专门为 x86 构建的 NHibernate 程序集。

于 2011-06-29T15:21:55.880 回答
2

你可以试试RunAsx86

从命令行运行时,我使用此工具以 x86 模式启动 .NET 应用程序。

于 2013-07-06T06:39:54.093 回答
0

I have run into similar problem before. I have a windows service using Crystal Reports, everything was fine on my 64b machine, I tuned everything - the project was built to use x86 architecture.

The problem occurred when deployed to different machine, the service was failing because the Crystal Reports engine could not load log4net.dll 1.2.10 assembly. I checked the directory - the version there was 1.2.11, my local directory contained the same version. The bindingRedirect did not work.

Then I checked GAC - CR dlls are signed and were added to GAC by installer, log4net 1.2.10 was there but the processor architecture was not x86. After adding the log4net 1.2.10 for x86 architecture it worked like a charm.

于 2014-02-18T10:29:55.300 回答
0

我在我的 c++ oracle 应用程序中遇到了同样的错误,我需要在 64 位机器上运行在 32 位机器上。错误的图像错误是由于 32 位和 64 位 dll 的混合造成的,所以我使用依赖walker 来查找混合了哪些 dll。在该应用程序中,我发现 oci.dll 是 64 位的,因为我安装了 64 位的 oracle 客户端,但所有其他 32 位的 dll。所以我在 64 位机器上安装了 32 位的 oracle 客户端并解决了这个错误。

于 2014-03-07T09:11:14.923 回答
0

如果它对任何人有帮助,我在使用 Oracle 64 位和 Windows 7 64 位时遇到了相同的症状。我单独留下了平台目标(没有更改任何项目设置)。相反,我只是安装了 oracle 32 位并解决了这个问题。请务必更新您的环境变量(即 ORACLE_HOME、PATH)以指向 32 位版本。

于 2012-06-06T22:33:15.423 回答