Search code examples
c#c#-4.0dllsystem.reflection

Dynamically loading DLL referencing other DLLs


I'm working in C# .Net 4.0

I have the following parts of the architecture:

  1. three "general" DLLs : X.dll , Y.dll, and Z.dll
  2. one "particular" DLL (A.dll) that is referencing the "general" DLLs
  3. one C# application that dynamically loads the A.dll (I use System.Reflection.Assembly ass = Assembly.LoadFrom(filename))

Since the application doesn't explicitly reference those "general" DLLs, I get an exception.

So my question is whether there is any chance to create the A.dll the way that would allow loading this DLL without the need to load those "general" DLLs. It seems that I can't transfer my A.dll without remembering about all the DLLs it is referencing.

I believe there is a good logic behind the way how it is done in C# 4.0, but maybe there are some exceptions to this?

Thanks for any help!


Solution

  • The problem here is your application only loads A.dll therefore that's the only DLL that's copied into the output directory so when A attempts to access code from X it fails because the app doesn't know where X is therefore can't load it.

    The easiest solution here would be to install the other "general" DLLs into the GAC. Or alternatively, just ship the "general" DLLs with your app because they won't be loaded unless you use A anyway, although, they are unnecessary bloat on your install/app size if they aren't required.