Troubleshooting: BadImageFormatException in .NET applications
Article: dts0223
Applies to: dtSearch Engine .NET API
Symptom: "An attempt was made to load a program with an incorrect format" message or System.BadImageFormatException running a .NET program on a 64-bit version of Windows
"An attempt was made to load a program with an incorrect format" means that you are trying to load a DLL that is mismatched with the platform. Specifically, there is a 32-bit vs. 64-bit issue.
Resolution 1. Use the 64- version of the dtSearch Engine's .NET API under 64-bit Windows
For information on using the 64-bit version of the dtSearch Engine, see How to use the 64-bit version of the dtSearch Engine.
If you get this error using the 64-bit version of the dtSearch Engine API, set your .NET project's "Platform Target" (in the Build tab of the project Properties) to x64 instead of "Any CPU".
For ASP.NET applications, you may need to set up the project to conditionally use either the 32-bit or the 64-bit version of the dtSearch .NET API, depending on the environment, because of the way Visual Studio builds ASP.NET applications. For more information, see How to use the 64-bit version of the dtSearch Engine.
Resolution 2. Mark your application as 32-bit
To use the 32-bit version of the dtSearch Engine on a 64-bit server, you can set some flags in the .exe to let .NET know to run the assembly as 32-bit and not 64-bit.
One way to do this is to change the Platform Target (in the Build tab of the project Properties) to x86 instead of "Any CPU".
Alternatively, you can use corflags.exe (a utility included with the .NET SDK) to set ILONLY- and 32BIT+ on your assembly.
If the application is running in 64-bit IIS, the application pool will also have to be configured to run 32-bit applications.