Using 32-bit dll on 64-bit system shows 0x8007000B Error

32bit-64bitc#-4.0dllimportiisvisual studio 2010

I have to use a third party DLL in my application. The DLL is a 32-bit and the system I am using is 64-bit OS.

I have Imported the 32-bit DLL in my DotNet application (framework-4.5) as below

 [DllImport("Sample.dll",
  EntryPoint = "Add",
  CharSet = CharSet.Ansi,
  CallingConvention = CallingConvention.StdCall)]
  public static extern int Add(int iA, int iB);

In IIS 7.5 – I have set "Enable 32-bit Application" as "True".

And also tried setting the Compiler Manager as – X86, x64 and Any CPU.

But all the attempt results in same Error as

 An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

How to resolve this Issue……

Best Answer

If you try to run 32-bit applications on IIS 7 (and/or 64-bit OS machine), you will get the same error. So, from the IIS 7, right click on the applications' application pool and go to "advanced settings" and change "Enable 32-Bit Applications" to "TRUE".

Restart your website and it should work.