Reputation: 101
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
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
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