0

I am working on an application where users can develop their own plugins as dll files. They need to put these dll files to a specific path so my application(C++) can load them and run. The problem is, when user develops a dll file depends another dll file and put both files to my dll path, my application can't find second dll file.

Ex:

DllA(C++) depends DllB(C#) my app loads DllA but can't find DllB and fails.

If user puts DllB into application binary path and DllA to specific dll path, I am able to execute plugin. I also tried to put DllB into various directories such as windows or system32 but it again fails. I also tried to add my dll path to PATH environment variable but no effect.

I am already executing SetDLLDirectory function to load DllA in the specific path. Since I've no control over user code, I can't make them to call this function in DllA code also. My question is that how can I force windows to search my specific dll path?

zgrw
  • 127
  • 11
  • How do you call DLLB from DLLA? Hard-coded string path or what? Did you add a reference to DLLB in DLLA in the solution explorer? Did you build DLLA correctly? Building the DLL will create a copy of the dependency DLLs in the bin folder meaning DLLB should be in the same path as DLLA. – jegtugado Jul 11 '16 at 06:54
  • 1
    Possible duplicate of [How to add folder to assembly search path at runtime in .NET?](http://stackoverflow.com/questions/1373100/how-to-add-folder-to-assembly-search-path-at-runtime-in-net) – Jim Jul 11 '16 at 07:01
  • @Ephraim I don't call it, it is user code and blackbox to my app. But in the example I've provided, user complies both in the same solution. DllA is a c++ code and DllB is a csharp code. User creates an instace of Class B from DllB in DllA. Also, both Dlls are in the same path (my dll path) and only dllB fails, but if I only move DllB to bin path (DllA is still in another path), it works – zgrw Jul 11 '16 at 07:06
  • @Jim I think it is not same because my application is C++ and I think I can't use Assambly.LoadFrom function. Only dllB is C# – zgrw Jul 11 '16 at 07:11
  • 1
    You have limited options when you can't subscribe the AppDomain.AssemblyResolve event. Technically it is possible to subscribe it in your C++ code but you have to host the CLR yourself. Do keep in mind that this has nothing to do with Windows, it is the CLR that needs to be able to find the assembly. You can use a subdirectory of your main C++ program's install directory and use a yourcppapp.exe.config file to tell the CLR about it. Not unreasonable. If it is a wildly unrelated directory then you have to install the assembly in the GAC. – Hans Passant Jul 11 '16 at 08:40
  • There is also this weird situation, it only look for dll under application path. I tried to alter PATH environment variable, put DLL into various other folders (such as windows, system32) but has no effect – zgrw Jul 11 '16 at 10:53

0 Answers0