C# doubt adding references at run time

Status
Not open for further replies.

Pragadheesh

In the zone
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

Canon EOS 600D / 1000D
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
 
OP
Pragadheesh

Pragadheesh

In the zone
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.
 
Status
Not open for further replies.
Top Bottom