Reputation: 3973
So I have three parts:
bridgeEntry
and calls methods in Lib.bridgeEntry
.Now I put them all into one directory and as expected, code from Lib is executed when I run NativeExe.
However, if I rearrange the directory structure like this:
├───exe
│ NativeExe.exe
│
└───libs
BridgeLib.dll
Lib.dll
things are a little bit different. Obviously running NativeExe.exe
in the exe
folder fails because it can't find BridgeLib.dll
. But that can be resolved by going to the libs
folder and running ..\exe\NativeExe.exe
. Now the application loads BridgeLib.dll
and jumps to bridgeEntry
. But now the CLR crashes with a FileNotFoundException
because it's looking for Lib.dll
in the executable's folder (exe
) and not in the bridge library's folder libs
.
This is just an overly simplified example and I can't change the directory structure. But how else could I solve this problem?
Upvotes: 2
Views: 655
Reputation: 564323
Your C++/CLI library could handle AppDomain.AssemblyResolve to properly specify the location of the C# assembly. This event is fired by the CLR when it fails to find the assembly at runtime, and gives you a chance to load the assembly yourself.
Upvotes: 2