0

When compiling a C# project which has external references, the referenced dlls are being copied to the project's output path (next to the exe).

When running the application, it expects to find the dlls next to the exe.

I'm looking for a way to spread my dll files into different directories Dlls for starters). And have the exe look for the dll files in those directories.

Example:

Let's say we have an application called "App" located under C:\App\App.exe, and also it uses a dll file called "App.dll" which is currently also located under C:\App.

I wish to create a new directory called C:\App\Dlls and move the App.dll file to there, while making sure that the App.exe file will know to look for the dll in the new location.

I've searched the internet and found the probing solution. Here's my code (edited "App.config" file):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas=microsoft-com:asm.v1">
      <probing privatePath="Dlls" />
    </assemblyBinding>
  </runtime>
</configuration>

I compiled my application, created the Dlls directory and moved all the dll files to that directory, but the application crashes.

What am I missing?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Idanis
  • 1,918
  • 6
  • 38
  • 69
  • 1
    Crashes with what error? – Jeroen Mostert Oct 14 '15 at 13:19
  • With: `System.IO.FileNotFoundException: Could not load file or assembly`. I also received `Set connectionId threw exception. Line number 5 and line position 71`. – Idanis Oct 14 '15 at 13:23
  • Well, creating a c:\app\bin directory and telling the CLR to go look in the Dlls subdirectory of course is not going to work. Beware the hosting process, it uses appname.vshost.exe.config. Use Fuslogvw.exe if you still have problems. And don't do this, it is just a bad idea. – Hans Passant Oct 14 '15 at 13:42
  • @HansPassant I meant `C:\App\Dlls` (I checked it with this), it was a typo. I edited the question. – Idanis Oct 14 '15 at 13:45
  • The value of `privatePath="Dlls"` should be the full path where you want runtime to search for assemblies i.e. `privatePath="C:\App\Dlls"` – vendettamit Oct 14 '15 at 13:52

1 Answers1

5

Found the solution, the file App.exe.config was missing from my base directory. That's why it didn't work. Now everything works smoothly.

Idanis
  • 1,918
  • 6
  • 38
  • 69