views:

441

answers:

3

Hi,

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.

+5  A: 

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.

Aamir
Thanks! It turned out to be one of the dependencies of MyCSharpAssembly.dll indeed. However, the problem was more involved: it wasn't sufficient for the dependencies to be in the same path as the DLL but they needed to be in the path of the .exe file (I suppose this is related to the 'APPBASE' property). Accepting this answer since it pointed me into the right direction.
Frerich Raabe
A: 

file no found? the C# Assembly no found? copy it to windows or system32 and have a try if failure,try to register best wishes

Edwin Tai
A: 

Do you have access to the C# assemblies source code? Can you run your managed C++ code in the debugger? It would be worthwhile to see a stack trace of the exception, this might give you more hints as to what is happening when the exception occurs.

I'd suspect that the crash may be related to the operation you're doing. As Aamir mention, the other possibility may be a dependency of the C# assembly...

Steve

Steve Wranovsky