I have a trouble with connecting DLL while running my application.
What I have?
I have Interfaces.dll where I defined interfaces which will be implemented by plugins. I've made new folder Plugins and copied dll to this folder.
public interface ITable { string ToString(List<int> _intArray); List<int> ToHex(string _stringArray); } public interface IAbout { string Description { get; } string Name { get; } string Author { get; } string Date { get; } string Link { get; } bool isDefault { get; } void About(); }
I have plugin TableBasic.dll which implements interfaces from Interfaces.dll. When I was making it, I've added Interfaces.dll to references from folder Plugins
public class Table : ITable, IAbout { ... }
I have application where I have static class Plugins with static method Load which loading specified dll imlemenitng specified interface. I've added Interfaces.dll from folder Plugins to application's references.
public static object Load(string path, Type seekingInterface) { Type DLL = Assembly .LoadFrom(path) .GetTypes() .First(t => seekingInterface.IsAssignableFrom(t) && typeof(IAbout).IsAssignableFrom(t)); return Activator.CreateInstance(DLL); }
Error
When I try to call load function as
Plugins.Load(@"D:\Repositories\Crystal\Plugins\TableBasic.dll", typeof(ITable));
I get exception:
System.InvalidOperationException: 'Sequence contains no matching element'
But I don't know why, it looks like my application and my plugin use different Interfaces.dll and interfaces ITable and IAbout in my application and in plugin is different or... I do not know what to suggest.
Could you please to help me?
Why not a duplicate: I want to get type that implements specifyied interface, getting type by assembly.GetType("MyType");
is not acceptable because I don't know name of type and I will not able to cast it to any interface if I didn't check type implements interface or not.