2

I have a dll file. I used it in a Windows Form Application (C#) without problem.

Now I want to use in my ASP.NET website (C#), and I import it like my Windows Application like this:

[DllImport( "mydll.dll" )]
static extern int myfunc(int i);

But when I run my web site and use myfunc method it shows this error:

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

I don't know what's the problem.

Some more info:

It's 64-bit dll. I have an x64 cpu (Intel core i7). I don't have source code of dll. I have an IIS on my local computer and I'm testing on it.

Rahmani
  • 857
  • 3
  • 14
  • 28
  • it's answered here: http://stackoverflow.com/questions/23215518/target-32-bit-or-64-bit-native-dll-depending-on-environment – thirdDeveloper Aug 30 '14 at 06:59

1 Answers1

1

You are probably running on x64 and your IIS is not setup to allow x86 assemblies.

Enable 32-bit DLLs in your Application Pool, as described here:

  1. Right click on your Application Pool
  2. Select Advanced Settings
  3. Change the value of "Enable 32-bit Applications" to true and click OK
demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
  • I did what you said, but it didn't solve the problem. – Rahmani Aug 30 '14 at 07:50
  • Give us some more information on your setup. Is it a 32-bit DLL? Do you have the DLL source code, can you recompile it to target x64? Is it happening locally or on server? Are you on x64? What version of IIS? – demoncodemonkey Aug 30 '14 at 07:53
  • 1
    It's 64-bit dll. I have a x64 cpu (Intel core i7). I don't have the dll source. I have an IIS on my local computer and I'm testing on it. – Rahmani Aug 30 '14 at 08:04
  • Setup the environment as described on answer, try to restart iis with iisreset – Max Aug 30 '14 at 09:10
  • @Max I did that, but I'm getting the same error yet. – Rahmani Aug 30 '14 at 14:59
  • 1
    There are any dependency on dll ? Check this http://stackoverflow.com/questions/2023766/an-attempt-was-made-to-load-a-program-with-an-incorrect-format-even-when-the-p and this http://stackoverflow.com/questions/16896718/error-when-trying-to-load-dll-an-attempt-was-made-to-load-a-program-with-an-in – Max Aug 30 '14 at 16:09