public MainForm() { InitializeComponent(); try { DirectoryInfo dir = new DirectoryInfo(Application.StartupPath); foreach (FileInfo file in dir.GetFiles("Plugin*.dll")) { string name = Path.GetFileNameWithoutExtension(file.Name); Assembly pluginAssembly = Assembly.Load(name); var plugins = from type in pluginAssembly.GetTypes() where typeof(ISpecialPlugin).IsAssignableFrom(type) && !type.IsInterface select type; foreach (Type pluginType in plugins) { ISpecialPlugin plugin = Activator.CreateInstance(pluginType) as ISpecialPlugin; specialPlugins.Add(plugin); } } } catch (Exception) { MessageBox.Show("An error occurred while loading special price plugins.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public MainForm() { InitializeComponent(); try { DirectoryInfo dir = new DirectoryInfo(Application.StartupPath); foreach (FileInfo file in dir.GetFiles("Plugin*.dll")) { string name = Path.GetFileNameWithoutExtension(file.Name); //not loading plugin 21-06-18 Assembly assembly = Assembly.Load(name); //here var plugins = from type in assembly.GetTypes() where typeof(ISpecialPlugin).IsAssignableFrom(type) && !type.IsInterface select type; foreach (Type pluginType in plugins) { ISpecialPlugin plugin = Activator.CreateInstance(pluginType) as ISpecialPlugin; specialPlugins.Add(plugin); } } } catch (Exception e) { MessageBox.Show("Error while loading special plugins"); Console.WriteLine(e); } }