How to force .NET application to run in 32bit mode

最后都变了- 提交于 2019-11-30 23:24:03

问题


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

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.

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

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

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

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?


Update:

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

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

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


回答1:


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.




回答2:


Correct, it sounds like the NHibernate assembly is built with AnyCPU as its platform target. You'll need an NHibernate assembly that is built for x86 specifically.




回答3:


You can try RunAsx86

I use this tool to start .NET applications in x86 mode, when run them from command line.




回答4:


In case it helps anybody, I was running into the same symptoms with Oracle 64 bit and Windows 7 64 bit. I left the platform target alone (did not change any project settings). Instead I simply installed oracle 32 bit and that resolved the issue. Be sure to update your environment variables (i.e. ORACLE_HOME, PATH) to point to the 32 bit version.




回答5:


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.




回答6:


I have got the same error in my c++ oracle application which i need to run on 64 bit machine build in 32 bit machine. the bad image error is due to intermixing of dlls of 32 bit and 64 bit so i used dependency walker to find which dlls are intermixed. In that application i found that oci.dll are of 64 bit as i have installed oracle client of 64 bit but all other dlls of 32 bit. so i installed the oracle client for 32 bit on 64 bit machine and resolved this error.



来源:https://stackoverflow.com/questions/6523075/how-to-force-net-application-to-run-in-32bit-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!