Search code examples
c#c++dllcrashmanaged

Crash when using C# Assembly from Managed C++ DLL


On a Windows XP system, I'm writing a Mangaged C++ library which calls code in a C# Assembly. Unfortunately, as soon as I start referencing a symbol in the C# Assembly, running the Managed C++ library fails with this error (I copied this from the XP crash dialog):

EventType : clr20r3
P1 : treeviewdemo.exe
P2 : 0.0.0.0
P3 : 4a5d6d62
P4 : system.windows.forms
P5 : 2.0.0.0
P6 : 4889dee7
P7 : 12fc     
P8 : ac
P9 : system.io.filenotfoundexception    

The Manged C++ library is basically just:

#using "C:\\MyCSharpAssembly.dll";

__declspec(dllexport) void callMangagedCode() {
  ManagedObject ^o = nullptr;
}

The '#using' itself doesn't seem to cause any problem, but as soon as I start using symbols form the C# DLL, I get problems. Does anybody know what's going on?

The system.io.filenotfoundexception part makes me think that some DLL is not being found, but I have no idea which or where it's looking.


Solution

  • Are all the dependencies of MyCSharpAssembly.dll available on the same path? If you are not sure, try loading the C-Sharp Assembly in ILDasm Tool to find out what are its dependencies.

    As a sanity check, also check that whether this C-Sharp DLL can be loaded from another C-Sharp executable or not.