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

北城余情 提交于 2019-12-18 07:46:40

问题


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


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/16539413/using-32-bit-dll-on-64-bit-system-shows-0x8007000b-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!