0

I am developing an "executor" which will execute DLLs by reflection. I will configure one DLL which implements an specific interface, the executor will load this DLL and execute the methods based on the interface.

In some cases the configured DLL can have another referenced DLLs that will not be in the directory.

My question is: how to load and execute this assembly don't having the physical DLL of the references?

Ex:

-Executor calls DLL "A".
-DLL "A" references DLL "B" and DLL "C".
-DLL "B" and DLL "C" are not in the directory. 
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Only a Curious Mind
  • 2,807
  • 23
  • 39
  • What do you expect to happen? Why are the assemblies not in the same directory, where are they? And what have you tried? See for example [Resolve assembly references from another folder](http://stackoverflow.com/questions/5260404/resolve-assembly-references-from-another-folder), [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), and so on. – CodeCaster Jun 07 '16 at 12:18
  • Then where are they ? Either they are located in one of the system directories/GAC and they will be loaded just fine when you load DLL "A", or they are not found and loading DLL "A" will fail. – nos Jun 07 '16 at 12:19
  • @nos I don't have the DLLs, the unique local that they are is in the references of DLL "A" :( – Only a Curious Mind Jun 07 '16 at 12:23
  • @CodeCaster I am trying to compile the DLL "A" to carry DLL "B" and DLL "C" together. Is it possible? – Only a Curious Mind Jun 07 '16 at 12:24
  • That is an entirely different question altogether, and it is called "merging assemblies". Try searching before asking a question both as question and in comments. – CodeCaster Jun 07 '16 at 12:25
  • @CodeCaster I tried a lot, my english is not so good and I didn't find using this term "Merging assemblies", thank you I will search about this. – Only a Curious Mind Jun 07 '16 at 12:26

2 Answers2

2

When a reference is resolved by the assembly loader at runtime, a missing physical file will always cause the binding process to fail with an exception (when the application needs the code from that assembly, it needs to be there, physically - that is, anywhere in the search path, including the GAC).

(even if you would find a way to intercept the loading process - which is possible in .NET - you won't get away without ultimately providing the IL of the referenced assembly somehow, be it by download, on-demand-compilation or whatever).

More information in "How the Runtime Locates Assemblies", here: https://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx

Your idea of removing additional dependencies makes sense though (reducing "DLL hell"), an option to consider would be the merging of multiple interdependent assemblies into a single binary, for example this free tool which is also available as a NuGet package: http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77
-1

Assuming you don't want to put these dlls into the working directory, you need to register dll B and C into the Global Assembly Cache (GAC)

You can refer to this wiki post or google GAC further info.

uTeisT
  • 2,256
  • 14
  • 26