0

There is some startup logic that gets all types implementing an interface from all referenced assemblies. I'm having some trouble getting the types from assemblies that were not yet required to load at that time.

The following code does NOT get the referenced dll:

Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select(Assembly.Load);

But with this little monkey patch, it does get it:

var forceIt = new SomeTypeFromThatNugetPackage();
Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select(Assembly.Load);

It also works if I do an explicit:

Assembly.Load(new AssemblyName("ThatNugetPackage"));

I've also tried the code from here which works nicely for project references but not for nuget references. Any ideas on how to force loading of these assemblies?

Laoujin
  • 9,962
  • 7
  • 42
  • 69
  • I thought the CLR uses delay load and JIT? –  May 04 '18 at 15:04
  • A project reference is basically the same as a Nuget reference - it's just a DLL that is referenced. If you don't explicitly use a type from that assembly though, it won't get loaded. You could loop through all DLLs in the bin directory and load them manually though. – DavidG May 04 '18 at 15:24
  • These nuget dlls are not in the bin directory. – Laoujin May 04 '18 at 15:33
  • Then load from the Nuget directory! But I think you will find in the compiled output that the DLLs will have been copied into the bin folder. – DavidG May 04 '18 at 15:34

0 Answers0