I’m trying to load and use a DLL at runtime and this works fine:
var pluggin = asm2.CreateInstance("ParserTest.Interface", true) as iPluggin;
But this doesn’t (I need to loop through the DLL files in a specific folder to find the right ones implementing iPluggin interface):
...
var asm = Assembly.LoadFrom(dll.FullName);
if (asm.GetExportedTypes().FirstOrDefault(q => q.GetInterface(tName) != null) == null) continue;
Project.ProcessList.Add(asm.CreateInstance(tName, true) as iPluggin);
...
Doing some research in debug mode I found out that:
asm.CreateInstance(tName, true)
returns the correct object, but when trying to cast it to iPluggin the result is null.
Any idea why?
Mistery solved althought I don’t understand it.
The DLL that defines de interface (SDK.dll) was among the ones being checked.
I removed it manually in my query and all woks as expected now.
This is my final code: