Trying to make an expandable application. I am looking for dll files, trying to find classes using this method that implement the ITranslator interface. In another project, everything works. In this - no. I can not understand the reason.
public List<ITranslator> LoadPlugins() { List<ITranslator> pluginList = new List<ITranslator>(); ITranslator plugin = null; Console.WriteLine(typeof(ITranslator).Module.FullyQualifiedName); try { foreach (var file in Directory.EnumerateFiles(PLUGINS_DIRECTORY, "*.dll", SearchOption.AllDirectories)) { Assembly asm = Assembly.LoadFrom(file); foreach (Type t in asm.GetExportedTypes()) { Console.WriteLine(t.Module.FullyQualifiedName); if (typeof(ITranslator).IsAssignableFrom(t)) { plugin = (ITranslator)asm.CreateInstance(t.FullName); pluginList.Add(plugin); } } } return pluginList; } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine(string.Format("ΠΡΠΎΠ±Π»Π΅ΠΌΠ° ΠΏΡΠΈ ΡΠΊΠ°Π½ΠΈΡΠΎΠ²Π°Π½ΠΈΠΈ Π΄ΠΈΡΠ΅ΠΊΡΠΎΡΠΈΠΈ Ρ ΠΏΠ»Π°Π³ΠΈΠ½Π°ΠΌΠΈ."), "ΠΡΠΈΠ±ΠΊΠ° ΠΏΡΠΈ Π·Π°Π³ΡΡΠ·ΠΊΠ΅ ΠΏΠ»Π°Π³ΠΈΠ½ΠΎΠ²"); return null; } } Should add to the list of plugins, but does not add.
D:\OneDrive\VSProjects\Translator\Translator\bin\Debug\ITranslator.dll D:\OneDrive\VSProjects\Translator\Translator\bin\Debug\Plugins\ITranslator.dll D:\OneDrive\VSProjects\Translator\Translator\bin\Debug\Plugins\YandexTranslator.dll
LoadPlugins()method is located and the classes with plug-ins use the same version of the assembly containingITranslator. If your plug-ins andITranslatorare located within the sameSolutionbefore checking the correctness of theLoadPlugins()method,LoadPlugins()recommend doingRebuild Solution. - sp7