2

I have an application "app.exe" (a C++ application) present in Release folder. I wrote a C++/CLI DLL (clr.dll) to call a C# DLL (csharp.dll). Both of these DLL's are in etc folder.

Release 
|-etc
   |-clr.dll
   |-csharp.dll
|-app.exe

app.exe is able to load clr.dll but clr.dll is not able to locate csharp.dll.

I used fuslogvw.exe to find out that the CLR is trying to search in Release folder.

Can someone help me out figure out a way to say CLR to search in my etc folder?

Mr.C64
  • 41,637
  • 14
  • 86
  • 162
dhiraj suvarna
  • 505
  • 7
  • 20
  • 1
    Storing DLLs in another folder is a pretty bad practice. Starting with the OS providing no help to locate clr.dll. Hopefully you didn't do something nasty like tinkering with the PATH environment variable. Much the same for the managed assembly, the CLR looks in the GAC first and the same directory as the EXE next. It *can* be convinced to look in a subdirectory, that requires an appname.exe.config file in the same directory as the native C++ app with a [`` element](https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/probing-element). – Hans Passant Sep 05 '17 at 16:38
  • @HansPassant: This application has already been developed, with binaries categorized into the folder structure. So when this application loads up, there are some paths added to PATH environment variable so that the application could find the dll's. Now according to this I have to place my dlls in a separate folder (not along with app.exe). Is config file the only way to go? – dhiraj suvarna Sep 05 '17 at 17:15
  • We can post good advice all day here. But if users don't want to listen to it because "it is categorized" and don't want to use the proposed solution either then they'll have to learn by attending the school of hard knocks themselves. – Hans Passant Sep 05 '17 at 18:51
  • @HansPassant: I think you got my intentions wrong. I am more that willing to listen to the advice, I was just making my situation clear to you. I will surely use your advice and update you with my findings. – dhiraj suvarna Sep 10 '17 at 10:58

1 Answers1

0

When you application is able to find the clr.dll than it should be easy to instruct the app domain to resolve other modules in this folder.

The clr.dll knows were it is loaded from (Win32: GetModulePathName).

Than you are able to use the already known links here in stackoverflow:

How to add folder to assembly search path at runtime in .NET?

xMRi
  • 14,982
  • 3
  • 26
  • 59