SOS!插件框架在查找DLL插件时出错!
插件框架的管理程序,\\Plugin目录 下是插件的时候没有问题,当放一个其它类型的DLL时报错:未处理 System.Reflection.ReflectionTypeLoadException
Message= "无法加载一个或多个请求的类型。有关更多信息,请检索 LoaderExceptions 属性。 "
private void PluginManage_Load(object sender, EventArgs e)
{
String pluginPath = Path.GetDirectoryName(Application.ExecutablePath)+ "\\Plugin ";
DirectoryInfo di = new DirectoryInfo(pluginPath);
if (!di.Exists)
{
di.Create();
}
FileInfo[] plugins = di.GetFiles( "*.dll ");
listView1.Items.Clear();
foreach (FileInfo plugin in plugins)
{
FindPluginFromAssembly(plugin);
}
CheckExistedPlugin();
}
private void FindPluginFromAssembly(FileInfo file)
{
Assembly assembly = System.Reflection.Assembly.LoadFile(file.f);
Type[] types = assembly.GetTypes(); //当Plugin目录下有别的类型*.dll文件时会出错,无法加载多个类型文件,在这里出错。
foreach (Type type in types)
{
if (type.GetInterface( "IPlugin ") != null)
{
ListViewItem lvi = new ListViewItem(type.Name);