0
votes

i'm facing a problem with using external dlls with mono at runtime. Suppose we have a framework dll containing an interface IMyInterface, a "plugin" project using this framework in which a class implements IMyInterface interface. This plugin, once deployed as dll, could be loaded from the framework itself at runtime, and all the classes which implements IMyInterface must be added to a collection within the framework. To do this, a type test must be done on all the types. Unfortunately, when I get all the types from the loaded dll, the type test fail even if the imported class is implementing a known interface. More precisely, the following statement

ImportedType.GetType().IsAssignableFrom(typeof(IMyInterface))

returns false, even if the type actually implements IMyInterface. I suppose this is about imported type to be a System.RuntimeType, and not System.Type. But how can I deal with this issue? May be the interface IMyInterface has different signature across the same assembly used by different solutions?

1

1 Answers

0
votes

IsAssignableFrom is one of the most confusing method

typeof(IMyInterface).IsAssignableFrom(myObject.GetType())
typeof(IMyInterface).IsAssignableFrom(ImportedType)

https://msdn.microsoft.com/en-us/library/system.type.isassignablefrom(v=vs.110).aspx