0

I'm trying to reference a .NET dll in a different folder for my program ex: Executable.exe --> bins --> ref.dll

I'm using Visual Studio 2019 to edit my project

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • 3
    Does this answer your question? [load a DLL reference from a different folder?](https://stackoverflow.com/questions/2009047/load-a-dll-reference-from-a-different-folder) or [Set Custom Path to Referenced DLL's?](https://stackoverflow.com/q/1892492/150605) – Lance U. Matthews May 13 '20 at 19:13

1 Answers1

2

Assuming this is a .NET Framework application, you can accomplish this by setting the <probing /> element (reference) in your application or machine configuration file. So, for your example, if you wanted to add the /bins folder to your assembly search path, you'd use:

<configuration>  
  <runtime>  
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
      <probing privatePath="bin;bins"/>  
    </assemblyBinding>  
  </runtime>  
</configuration>  

Obviously, this will only work if you know the locations upfront. If you need to dynamically configure the search path at runtime, you'll need to use something like AppDomain.AssemblyResolve event. That is a bit more involved, but provides more flexibility if you need it.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
  • Aside, do you recall if this addressed your problem? If so, would you mind marking it as the accepted answer? (By clicking the checkmark below the voting buttons.) That will mark this question as answered—and reward me with a bit of reputation in the process! (If you don't recall, or it didn't address your question, then just ignore this.) – Jeremy Caney Jul 23 '21 at 18:48