从 C++ 托管的 dll 抛出的 C# 异常 - EEFileLoadException * __ptr64 [英] C# exception thrown from a C++ managed dll - EEFileLoadException * __ptr64

查看:79
本文介绍了从 C++ 托管的 dll 抛出的 C# 异常 - EEFileLoadException * __ptr64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个普通的 C# 控制台程序中得到这个错误,该程序使用作为 C++ CLI 项目的构建输出生成的 DLL.在那里我有一个简单的 DumbThing public ref class 和一个静态方法.我想简单地调用该函数或至少实例化一个小的 DumbThing 对象,然后看到 C# 可以调用它从 C++ CLI 生成的 DLL 中获取的代码,但它不起作用,因为它引发了一个让我更加困惑的错误:

I get this error from within a normal C# console program that's consuming a DLL produced as the build output of a C++ CLI project. There I have a simple DumbThing public ref class with a static method. I'd like to simply call that function or at least instantiate one tiny DumbThing object and see that C# can call code that it gets from a C++ CLI born DLL, but it's not working as it throws an error that puzzles me even more:

First-chance exception at 0x000007fefd2acacd (KernelBase.dll) in DumbTest.exe: Microsoft C++ exception: EEFileLoadException * __ptr64 at memory location 0x007fc228..

更新:在原始例外之下,还有另一个第一次机会例外:

UPDATE: below the original exception, there's another first chance exception:

First-chance exception at 0x77cace3b (ntdll.dll) in DumbTest.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.

一位同事向我指出这可能是编译时问题(一些选项),但我不知道是什么原因导致的.任何人都可以提供一些起点提示吗?

A colleague pointed out to me that it might be a compile time issue (some options), but I don't have any clues what could cause it. Could anyone please provide some starting point hints?

推荐答案

这可能是一个小问题.如果您为特定平台编译了 C++/CLI 项目,请确保您的 C# 项目已相应地设置其平台.C# 项目的默认值是任何 CPU",这会导致 JIT 编译器在 64 位架构上生成 x64 代码.如果您的 C++/CLI 项目是为 x86 构建的,那么它就无法加载到 64 位机器上的 x64 进程中.

It's probably a bitness issue. If you compiled your C++/CLI project for a specific platform, be sure that your C# project has set its platform accordingly. Default for C# projects is "Any CPU" which causes the JIT compiler to generate x64 code on a 64-bit architecture. If your C++/CLI project was built for x86 then it can't be loaded into a x64 process on a 64-bit machine.

这篇关于从 C++ 托管的 dll 抛出的 C# 异常 - EEFileLoadException * __ptr64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆