Download all .NET reference assemblies, even if they are not explicitly used in the code

We have a Windows service that uses Autofac when we try to load referenced assemblies, not all are listed as some containing objects that we do not use anywhere else in the application, but interface implementations where we should be included. The following method loads assemblies:

private IEnumerable<Assembly> GetReferencedAssemblies(Assembly assembly)
{
  var assemblyNames = assembly.GetReferencedAssemblies();

  List<Assembly> assemblies = new List<Assembly>();
  assemblies.Add(assembly);
  foreach (var item in assemblyNames)
  {
    var loadedAssembly = System.Reflection.Assembly.Load(item.FullName);
    assemblies.Add(loadedAssembly);
  }

  return assemblies;
}

If we make a fictitious reference to the object contained in the assembly, then it loads the assembly, and the types are created using autofac, if we delete the dummy object, the assembly will no longer be included.

Is it possible to include all referenced assemblies regardless of whether you directly use the object there (given that we still need it, since interface implementations are implemented there).

ASP.NET, DLL .

+5
1

, , , . AppDomain Assembly.Load(). , . , , , , , .

+1

All Articles