0

I have a folder "DLLs" where all assemblies are kept related to my project. As per current practice, all the exes (of my project) copy the DLLs from this folder to their "own" folder (each exe has its own folder like SupportTools/DbAccess, SupportTools/WebReq ..etc) and when a software is run it picks the DLLs from its "own" folder by default.

I feel this is unnecessary overhead. So I want to eliminate this copy. I referred yo below link and loaded assemblies from custom path (from DLLs)

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

But not there is another problem arising.

  • Say I have SomeAssembly.dll
  • I loaded it from DLLs

    Assembly.LoadFrom(customPath + "SomeAssembly.dll")

  • Now this SomeAssembly.dll depends on SomeOther.dll which is needs at the time of below code

    assembly.CreateInstance(.."SomeAssembly.dll"..)

  • It fails at this point, as it (might be) searching in current and SomeOther.dllisn't present in current application's "own" folder

enter image description here

(Names hidden for obvious reasons)

How can I make it to look at the custom path at this time ?

Community
  • 1
  • 1
SimpleGuy
  • 2,764
  • 5
  • 28
  • 45
  • "I feel this is unnecessary overhead" - why do you think so? – Dennis Feb 25 '15 at 05:50
  • @Dennis **1.** Coz size of entire application increases due to multiple copies of DLLs **2.** If in future i add a new DLL which is used by exsiting DLLs, each application would need to add a copy to copy that DLL also to their path – SimpleGuy Feb 25 '15 at 05:53
  • 3
    If you want to reduce application size, just refactor your folder structure: put all executables in the same folder, make sub-folder "DLLs" and add "probing/privatePath" (https://msdn.microsoft.com/en-us/library/823z9h8w%28v=vs.110%29.aspx) into config file for each executable. Otherwise, if those executables must be placed into different folders (for some reasons), copying shared assemblies is a right way to go, and it completely fits .NET deployment ideology via xcopy. Another way is to put them into GAC. Actually, `LoadFrom` could be very error-prone and should be avoided im most scenarios. – Dennis Feb 25 '15 at 05:59

0 Answers0