Pages

Wednesday, April 1, 2009

BadImageFormatException in IIS 7.0 on 64-bit Windows 2008

When hosting a WCF service in IIS 7 on my 64-bit Windows 2008 machine I got the following error:

System.BadImageFormatException: Could not load file or assembly 'APToolkitNET' or one of its dependencies. An attempt was made to load a program with an incorrect format.

To resolve this I had to set the "Enable 32-Bit Applications" ([enable32BitAppOnWin64]) to true on the applicable application pool.

See also:


I've also run into the same issue with the Application Pool for a Sitecore CMS 6 install.

Server Error in '/' Application.

Could not load file or assembly 'System.Data.SQLite, Version=1.0.48.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' 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 'System.Data.SQLite, Version=1.0.48.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.

6 comments:

  1. Thanks a lot! It was driving me crazy..

    ReplyDelete
  2. Thank you very much!!!! This bug was driving me crazy, you help came in good times =)

    ReplyDelete
  3. You saved me. I was banging my head hardly to find a solution on this couple of days. My problem and solution as described below,

    1. I have a 32 bit third party dll which i have installed in 2008 R2 machine which is 64 bit.
    2. I have a wcf service created in .net 4.5 framework which calls the 32 bit third party dll for process. Now i have build property set to target 'any' cpu and deployed it to the 64 bit machine.
    3. when i tried to invoke the wcf service got error "80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG"
    4. Now i used ProcMon.exe to trace the com registry issue and identified that the process is looking for the registry entry at HKLM\CLSID and HKCR\CLSID where there is no entry.
    5. Came to know that Microsoft will not register the 32 bit com components to the paths HKLM\CLSID, HKCR\CLSID in 64 bit machine rather it places the entry in HKLM\Wow6432Node\CLSID and HKCR\Wow6432Node\CLSID paths.
    6. Now the conflict is 64 bit process trying to invoke 32 bit process in 64 bit machine which will look for the registry entry in HKLM\CLSID, HKCR\CLSID. The solution is we have to force the 64 bit process to look at the registry entry at HKLM\Wow6432Node\CLSID and HKCR\Wow6432Node\CLSID.
    7. This can be achieved by configuring the wcf service project properties to target to 'X86' machine instead of 'Any'.
    8. After deploying the 'X86' version to the 2008 R2 server got the issue "System.BadImageFormatException: Could not load file or assembly"
    9. Solution to this badimageformatexception is setting the 'Enable32bitApplications' to 'True' in IIS Apppool properties for the right apppool.

    ReplyDelete