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
}
}
Marek

Marek

Currently working as SharePoint Developer combining both back-end & front-end development scenarios. Also enthusiastic about Office 365 & Azure solutions.

You may also like...

Leave a Reply

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