如何强制 .NET 应用程序以 32 位模式运行 [英] How to force .NET application to run in 32bit mode

查看:38
本文介绍了如何强制 .NET 应用程序以 32 位模式运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run my .NET 3.5 WinForms application on a Win7 x64. The application uses NHibernate and the System.Data.OracleClient to access an Oracle database. The Oracle client is 32bit.

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

When starting up the app I get the following error message

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

Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.

为此,我将我的构建定位到 x86 平台:

In response to that, I targetted my build to the x86 platform:

令我惊讶的是,当尝试在 Win7 平台上执行该新版本时,出现了完全相同的错误消息.

To my surprise, the very same error message appeared when trying to execute that new build on the Win7 platform.

NHibernate 程序集在运行时通过 Assembly.Load("..."); 加载.

The NHibernate assembly is loaded at runtime by Assembly.Load("...");.

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

Could it be that the NHibernate DLL still runs in 64 bit mode whilst the host exe runs in 32 bit mode. That sounds strange to me. Or could it be that for whatever reason, my application runs in 64 bit mode even though it was targeted to x86?

更新:

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

I checked my binary using CorFlags, and it is marked 32 bit:

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后缀.

I also checked it in Task Manager, and it has a *32 suffix.

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

I also tried and used CorFlags to add the 32bit flag to all assemblies that come with my application. It still yields the same error message.

我很困惑……很困惑……很困惑……

I'm puzzled... puzzled... puzzled...

推荐答案

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

32-bit processes cannot load 64-bit DLLs and vice versa (see this for details). That means that if your process successfully loaded a 64-bit DLL then it most definitely is a 64-bit process. You can verify that in Task Manager (as Lasse suggested) or via other means described here. That article also has more information on .Net on Windows x64.

这篇关于如何强制 .NET 应用程序以 32 位模式运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆