Loading a class library dynamically

Fazzyer

Member
Joined
Jul 29, 2005
Messages
16
Programming Experience
5-10
Hi all!

I want to write a program that can be extended with class-DLLs. All class-DLLs have the same methods.

I thought abaout the following procedure: When the application is starting, it looks, which DLLs are in it's folder (for example "test1.dll" (class: CTest1) and "test3.dll" (class: CTest3)), loads them and creates instances from the classes(Dim test1 As New CTest1, Dim test3 As New CTest3).

All class-DLLs have the same functions, for example DoSomething() (test1.DoSomething, test3.DoSomething).

But how can I do this at runtime? To create an instance from a class in a DLL, normally I have to add the DLL to the "References"-section in the "Solution Explorer" AND add the line "Imports CTestX" (X = number) to my code... how can I do this at runtime?

Please help me, any hint is welcome! :)

Thanx, Fazzyer
 
Hi,

You can use following sample code.

Private objAssemblyName As [Assembly]
objAssemblyName = [Assembly].LoadFile(strAssName)

// where strAssName may be test1.dll or test3.dll (physical path)

Dim obj as Object = objAssemblyName.CreateInstance("CTest1")
//May be CTest3 as per yr requirement

That's all u want to do.

Thanks.
 
Back
Top