Нашёл пример организации программы с плагинами. (
http://www.codeproject.com/KB/cs/pluginsincsharp.aspx
Подключение плагинов производится такой вот функцией:
private void AddPlugin(string FileName)
{
//Create a new assembly from the plugin file we're adding..
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
//Next we'll loop through all the Types found in the assembly
foreach (Type pluginType in pluginAssembly.GetTypes())
{
if (pluginType.IsPublic) //Only look at public types
{
if (!pluginType.IsAbstract) //Only look at non-abstract types
{
//Gets a type object of the interface we need the plugins to match
Type typeInterface = pluginType.GetInterface("PluginInterface.IPlugin", true);
//Make sure the interface we want to use actually exists
if (typeInterface != null)
{
//Create a new available plugin since the type implements the IPlugin interface
Types.AvailablePlugin newPlugin = new Types.AvailablePlugin();
//Set the filename where we found it
newPlugin.AssemblyPath = FileName;
//Create a new instance and store the instance in the collection for later use
//We could change this later on to not load an instance.. we have 2 options
//1- Make one instance, and use it whenever we need it.. it's always there
//2- Don't make an instance, and instead make an instance whenever we use it, then close it
//For now we'll just make an instance of all the plugins
newPlugin.Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
//Set the Plugin's host to this class which inherited IPluginHost
newPlugin.Instance.Host = this;
//Call the initialization sub of the plugin
newPlugin.Instance.Initialize();
//Add the new plugin to our collection here
this.colAvailablePlugins.Add(newPlugin);
//cleanup a bit
newPlugin = null;
}
typeInterface = null; //Mr. Clean
}
}
}
pluginAssembly = null; //more cleanup
}
Переделал все под свои нужды, но случайно забыл потереть старые плагины в папке plugins
Получил исключение на функции pluginAssembly.GetTypes() :
{"Не удается загрузить один или более запрошенных типов. Обратитесь к свойству LoaderExceptions для получения дополнительных сведений."}
А в LoaderExeptions :{"Не удалось загрузить тип \"PluginInterface.IPlugin\" из сборки \"PluginInterface, Version=1.0.3222.38063, Culture=neutral, PublicKeyToken=null\".":"PluginInterface.IPlugin"}
Подскажите как сделать так, чтобы правильно перечислить доступные типы в сборке Assembly ?