# C# doubt adding references at run time



## Pragadheesh (Mar 11, 2009)

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)

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)

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.


----------

