3

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?

teodron
  • 1,410
  • 1
  • 20
  • 41
  • 1
    Is your C# project set to compile for 64-bit specifically (not always a good thing)? Project --> Properties --> Build --> Platform Target. Try setting that to x86 if it is not set as such. – Chris Barlow Jul 20 '12 at 18:22
  • First-chance exceptin is a run-time thing. Are you able to put a breakpoint in your C# code at the start of Main and reach that before this exception? That will clarify whether it's a loader problem or not. – Peter Ritchie Jul 20 '12 at 20:03
  • No, any mention of the dumb class in the main function will throw this exception, ignoring any breakpoints. It must be a load problem then.. but I don't know what might be causing it.. maybe the C++ generated dll needs other assemblies? (it has everything in its residence folder and walking its dependencies doesn't reveal any nastiness).. – teodron Jul 20 '12 at 20:37

1 Answers1

3

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.

Paul Michalik
  • 4,331
  • 16
  • 18
  • Thanks for the hint, I double checked it, the dll is 64 bit, the c# application platform is also 64 bit, the process is 64 bit. Same outcome, save another first chance exception I forgot to mention. Hence, I've update the question. – teodron Jul 23 '12 at 08:00
  • Make sure not only your projects but also you 3rd party dependencies are 64-bit. Just had this issue - our 64-bit software referred a x86 version of SlimDX, compiling well but crashing at run time. – tomascz Jun 03 '20 at 09:25