7

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......

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Renuka
  • 206
  • 2
  • 6
  • 14
  • May be you can find your answer here – Aakash May 14 '13 at 09:32
  • possible duplicate of [How to run VS 2010 Local IIS in 32 bit mode](http://stackoverflow.com/questions/10711498/how-to-run-vs-2010-local-iis-in-32-bit-mode) – Hans Passant May 14 '13 at 10:03
  • see this post about the 0x8007000B Error http://stackoverflow.com/questions/18007967/net-framework-error-hresult-0x8007000b/36353971#36353971 – JinSnow Apr 01 '16 at 10:28

3 Answers3

2

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.

0

Check the Build checkbox in the Configuration Manager for your executable, what CPU it is running for, probably you have Any CPU build there. Restart Visual Studio then to not complain that it couldn't debug the assembly.

Right-click on the project and open Properties->Compile->Advanced Compile Options->Target CPU: it should match the "Platform" you are building. That is, if you are building "Any CPU" then "Target CPU" should say "Any CPU". Go through all of your Platforms by making them active and check this setting.

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.

4pie0
  • 29,204
  • 9
  • 82
  • 118
  • Hi. I have done all the things u mentioned in 1st para and also in 3rd para. But it result in same error... When tried to see the Compiler Option, the Properties has no option like "Compile->Advanced Compiler Options" – Renuka May 14 '13 at 10:05
  • it depends on particular project, what your application is exactly? – 4pie0 May 14 '13 at 10:27
0

I have experienced this problem both when I was running a 32-bit dll on a 64-bit machine and when using the DllImport method and forgetting to install the appropriate redistributable library for what I was calling. I've needed to install the visual c++ redistributable on occasion when a called library had a dependency on that and I've also needed to install the Intel Visual Fortran redistributable - when calling a Fortran function from a .NET library.

Chris Townsend
  • 3,042
  • 27
  • 31