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

January 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031