【问题标题】:EEFileLoadException When Loading C++ DLL in Managed DLL在托管 DLL 中加载 C++ DLL 时出现 EEFileLoadException
【发布时间】:2013-05-28 15:50:54
【问题描述】:

我有一个非托管 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。

【问题讨论】:

  • 我需要查看堆栈跟踪才能进行调用。但首先将调试器切换到托管模式,以便查看实际的托管异常。

标签: c# c++ dll c++-cli


【解决方案1】:

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

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

【讨论】:

  • 哇,这需要永远!是的,问题出在我的 C++ 库链接的某个库上。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    相关资源
    最近更新 更多