DIGIT-ARC read-only archive · snapshot: July 23, 2026

C# doubt adding references at run time

3 posts · originally from https://geek.digit.in/community/threads/c-doubt-adding-references-at-run-time.110503/

Pragadheesh
Pragadheesh Original post #1
Mar 11, 2009 at 10:41 AM
hi,

how can i add an assembly(dll) as reference in a C# project at run time.?! i need to add a reference at run time.!?


Consider i ave a class library(dll) in "C:\Documents and Settings\Pragadheesh\My Documents\Visual Studio 2005\Projects\qwerty\qwerty\bin\Debug\qwerty.dll"

i need to add this dll as reference in my project. how can i do this at run time.?
astroutkarsh
Mar 13, 2009 at 12:09 PM
Sample Code Snippet

System.Reflection.Assembly extAssembly;
Object objExtAssembly;
Type tpExtAssembly;

extAssembly = System.Reflection.Assembly.LoadFile(AppRelativeVirtualPath.ToString () + "\\<AssemblyFileName>.dll");
tpExtAssembly = extAssembly.GetType("<Assembly>.<yourClass>");
objExtAssembly = Activator.CreateInstance(tpExtAssembly);

Ref Links
1. *msdn.microsoft.com/en-us/library/25y1ya39.aspx
2. *social.microsoft.com/Forums/en-US/vblanguage/thread/657c688e-803a-4d1f-a50b-6fad5bdeec6a
Pragadheesh
Mar 16, 2009 at 1:06 PM
i got the answer. here it is.

Assembly asm = Assembly.LoadFile(@"assembly_path");
Type type = asm.GetType("assembly.class", false, true);

using this we can add references at run time.