nandaka
nandaka

Reputation: 101

Instantiating a class from different .dll using reflection based on the class name?

Is there any way to instantiate a class based it name from different project/.dll without using dll = Assembly.LoadFile(@"c:\Test.dll"); and do dll.CreateInstance(className);

I want to be able to load different class which implementing a common Interface in my application without need recompiling (something like a plugin). The dll is in the application path.

Upvotes: 0

Views: 783

Answers (2)

C.Evenhuis
C.Evenhuis

Reputation: 26446

I don't think there is any way to find a Dll based on only a class name or an interface a class implements, except for just finding and opening each Dll in the directory. You could use the ReflectionOnlyLoad* methods to reduce some overhead while finding the correct Dll.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1503859

You'll need to know which assembly to load it from somehow... then you can use Type.GetType(name) where the name you pass is qualified with the assembly name as well.

Upvotes: 1

Related Questions