在托管DLL中加载c++ DLL时出现eefileloadeexception

EEFileLoadException When Loading C++ DLL in Managed DLL

本文关键字:DLL eefileloadeexception c++ 加载      更新时间:2023-10-16

我有一个非托管的c++ DLL,我想从c# exe中调用。我研究了可能的解决方案,在我看来,最好的办法是使用c++/CLI作为非托管c++类的包装器。所以我写了一个c++/CLI类,看起来像这样,并被编译成一个DLL(我知道它应该有一个析构函数和一个终结器,但到目前为止,代码不会进入Main函数,所以为了简单起见,我把它们排除了):

#include <cppheader.h>
using namespace System;
namespace DependencyInterface
{
  public ref class DependencyTester
  {
  public:
    DependencyTester()
    {
      _class = new CPPClass();
    }
  private:
    CPPClass* _class;
  };
}
然后我有一个c#可执行文件,看起来像这样:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DependencyInterface;
namespace DependencyTest2
{
    class Program
    {
        static void Main(string[] args)
        {
            DependencyTester tester;
        }
    }
}

不幸的是,当我尝试运行代码时,我得到了以下c++异常:

First-chance exception at 0x000007fefd5a9e5d in DependencyTest2.exe: Microsoft C++ exception: EEFileLoadException * __ptr64 at memory location 0x0094ca58..

我试图在Main的第一行设置一个断点,但是在执行到达该点之前抛出了异常。如果我点击"继续"(我使用的是MVS 2010),我得到这个:

First-chance exception at 0x76d8c5e2 in DependencyTest2.exe: 0xC0000005: Access violation reading location 0x0000000000000020.

有人有什么建议吗?这是在Windows 7 x64上,所有内容都是为x64编译的,包括c++ DLL。

eefileloadeexception表示可执行文件无法找到或加载它的一个依赖项。当然,这可能有不同的原因(路径问题,混合配置,混合平台)。

一个好的开始是在你的DLL的/可执行文件上使用Dependency Walker(确保使用x64版本)

我有一个类似的问题,我在c#项目中引用了一个dll,并且引用的dll本身依赖于我没有包含在我的解决方案中的其他一些dll。在我的解决方案中添加了对缺失dll的引用后,问题得到了解决。或者,您可以将缺失的dll直接复制到应用程序目录。使用Dependency Walker没有帮助,因为他们没有显示丢失的dll的名称。