ASP.NET: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. on Win7 64bit

These message as blow:

Server Error in '/WebService' Application.
--------------------------------------------------------------------------------

Could not load file or assembly '******' or one of its dependencies. An attempt was made to load a program with an

incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace

for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'DHI.DHIfl' or one of its dependencies.

An attempt was made to load a program with an incorrect format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and

location of the exception can be identified using the exception stack trace below. 

Assembly Load Trace: The following information can be helpful to determine why the assembly 'DHI.DHIfl' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

以上参考:http://www.lazyasscoder.com/Article.aspx?id=90&title=System.BadImageFormatException%3A+An+attempt+was+made+to+load+a+program+with+an+incorrect+format.++on+Win2k8+64bit%2C+IIS7%2C+Oracle

My .NET web service used to live in a 32-bit Windows 2003 server running under IIS6 connecting to an Oracle database.  I had to migrate my web service to a new 64-bit Windows 2008 server running IIS7.  This is when the following error started:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
  at Oracle.DataAccess.Client.OpsTrace.GetRegTraceInfo(UInt32& TrcLevel)
  at Oracle.DataAccess.Client.OraTrace.GetRegistryTraceInfo()
  at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)



What the hell does this error means, no body knows.  After alot of googling and playing around on the server with IIS, I finally figured out the solution to my problem.
Because my web service application was using an older 32-bit Oracle driver, I had to force IIS7 to run in 32-bit mode and this is how I did it.
Under IIS7, my web application was running in an application pool.
  1. Right clicked over the AppPool name 
  2. Selected Advanced Settings...
  3. Under the General Section, set Enable 32-Bits Application to True
  4. Click OK, you may want to recycle the application pool just to be sure.
Done, nice and simple. No code changes required.


 

贴图:

原文地址:https://www.cnblogs.com/lifuyun/p/lifuyun2011092301.html