简体   繁体   English

部署的64位C#应用程序无法加载非托管DLL

[英]Deployed 64bit c# application can't load unmanaged dll

I have a 64bit web application written in c# deployed to IIS on both windows server 2008 (IIS 7) and windows server 2012 (IIS 8). 我有一个用c#编写的64位Web应用程序,该应用程序已部署到Windows Server 2008(IIS 7)和Windows Server 2012(IIS 8)上的IIS。

Part of the application involves accessing an unmanaged c++ DLL from c# code. 该应用程序的一部分涉及从c#代码访问非托管的c ++ DLL。 This call is failing when I deploy to IIS. 当我部署到IIS时,此调用失败。 I get the classic: 我得到经典:

An attempt was made to load a program with an incorrect format. 试图加载格式错误的程序。 (Exception from HRESULT: 0x8007000B) (来自HRESULT的异常:0x8007000B)

I have read many threads on the topic, including: 我已经阅读了有关该主题的许多主题,包括:

An attempt was made to load a program with an incorrect format ERROR 试图加载格式错误的程序ERROR

“An attempt was made to load a program with an incorrect format” even when the platforms are the same 即使平台相同,也“尝试加载格式错误的程序”

But I don't think they apply as 但我不认为它们适用于

  1. I have a 64 bit application. 我有一个64位应用程序。
  2. It's compiled as x64 编译为x64
  3. It's deployed as x64 部署为x64
  4. I have verified it is running under an x64 IIS appPool. 我已经验证它正在x64 IIS appPool下运行。
  5. enable32bitapplications is set to false . enable32bitapplications设置为false
  6. Both the c# dll importing and the unmanaged dll are compiled to 64bit. C#dll导入和非托管dll都被编译为64位。
  7. I have deployed to IIS on the server machines in both Release and Debug mode - no difference. 我已经以发布和调试模式在服务器计算机上部署了IIS-没什么区别。

There are 32 bit dlls in the application, but they are in completely separate projects which are not referenced by, nor reference, the project that is throwing the error. 应用程序中有32位dll,但是它们位于完全独立的项目中,这些项目没有被抛出错误的项目引用或引用。

For additional information, it runs fine on both my local machine in IIS express AND my local machine when deployed through IIS (windows 7), so there is a disconnect somewhere and I can't track it down. 有关其他信息,它在IIS Express中的我的本地计算机上以及通过IIS(Windows 7)部署时在我的本地计算机上都运行良好,因此某个地方存在断开连接,我无法对其进行跟踪。

Additional info: 附加信息:

The unmanaged DLL does have dependencies on: 非托管DLL确实依赖于:

  • Kernel32.dll 内核32.dll
  • Advapi32.dll Advapi32.dll
  • Crypt32.dll Crypt32.dll
  • User32.dll User32.dll
  • Version.dll 版本.dll

I realize these are 32bit I thought these were 32bit, but on a 64 bit machine these live in System32, so I'm not sure... but if so, how can I get it to compile as the unmanaged DLL itself is compiled to 64 bit. 我意识到这些是32位的,我以为是32位的,但是在一台64位的机器上,它们都存在于System32中,所以我不确定...但是,如果是这样,当将非托管DLL本身编译为64位。

Also, why would it work locally for me? 另外,为什么它对我本地有效?

Also, I have (just for kicks and skittles) set Enable32BitApplications to True and I get the same error, as my project is a 64 bit project and references a 64bit unmanaged DLL, which can't run in a 32 bit process. 另外,我(仅适用于踢踢和吃喝玩乐)将Enable32BitApplications设置为True,并且遇到相同的错误,因为我的项目是64位项目,并且引用了不能在32位进程中运行的64位非托管DLL。

There was an additional dependency for the unmanaged DLL that was a c++ redistributable dll. 对于非托管DLL,还有一个附加依赖性,它是c ++可再发行的dll。 The copy of that DLL on the machine was 32 bit, once I swapped out the version to be 64 bit, it loaded just fine. 在机器上该DLL的副本为32位,一旦我换出64位版本,就可以正常加载了。

Lesson learned, all dependencies of the DLL must be present and the correct Bitness. 从中学到的知识,必须存在DLL的所有依赖关系以及正确的Bitness。

您需要在IIS中将Enable32bitApplications设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM