GetReferencedAssemblies not returning all referenced assemblies

GetReferencedAssemblies is used to retrieve all referenced assemblies by assembly. But sometimes
this list is not complete, and does no contain all assemblies, that are simply added to project references in Visual Studio.

Assembly.GetExecutingAssembly().GetReferencedAssemblies()

The problem is, that assembly is loaded to AppDomain “on demand” – lazy load – you must first “call/use something” from that assembly.

You need to explicitly call a static function or create some object from referenced assembly in your source assembly.

//Referenced assembly dll
public class DummyInit
{

}

//Source assembly, that is referencing above assembly
using Referenced.Assembly.NameSpace;

public class SomeClass
{
public function SomeFunc()
{
DummyInit di = new DummyInit();

//Assembly.GetExecutingAssembly().GetReferencedAssemblies() now should contain Referenced Assembly
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

About me

I am web developer, tech enthusiast and fitness junkie 🙂

Calendar

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031