The error message I was seeing is IIS7 was:
Could not load file or assembly 'MyDllFile' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Could not load file or assembly 'MyDllFile' 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 'MyDllFile' 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.
Here is how I was able to force IIS7 to use x86 mode on a 64 bit version of Windows Server 2008:
- First I needed to change my C# applications to compile in x86 mode rather than "Mixed Platforms".
I did this by right clicking my solution and opening the Properties and then selecting the Configuration Properties tree branch in Visual Studio 2008. - Next I opened IIS7 Manager (Internet Information Services Manager):
Control Panel -> Administrative Options -> Internet Information Services Manager - In the IIS7 Manager I selected the Application Pools leaf for my server.
- I right clicked on the Classic .Net AppPool.
(you may want to use the Default AppPool depending on if you application was originally designed for IIS7 )
And selected Advanced Settings... - Under Advanced Sttings there is an option called
"Enable 32-Bit Applications"
Switch that option to True - Open your website and find your Application.
Change your application to use the Classic .Net AppPool
(or Default AppPool depending on your application ) - Restart IIS7