[英]Reflection.ReflectionTypeLoadException for MahApps DLL
[英]ReflectionTypeLoadException on DLL load
我正在嘗試使用MEF實現插件框架。 我有3個項目:
現在在主機中,我嘗試加載插件assemly dll(僅顯示應加載dll的類):
public class SafeDirectoryCatalog : ComposablePartCatalog
{
private readonly AggregateCatalog _catalog;
public SafeDirectoryCatalog(string directory)
{
var files = Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories);
_catalog = new AggregateCatalog();
foreach (var file in files)
{
try
{
var asmCat = new AssemblyCatalog(file);
if (asmCat.Parts.ToList().Count > 0)
{
_catalog.Catalogs.Add(asmCat);
}
}
catch (ReflectionTypeLoadException)
{
}
catch (BadImageFormatException)
{
}
}
}
public override IQueryable<ComposablePartDefinition> Parts
{
get { return _catalog.Parts; }
}
}
上
var asmCat = new AssemblyCatalog(file);
我可以看到,有一個“ ReflectionTypeLoadException”,零件清單是空的:
這是我的接口定義(輸出主機和插件項目中引用的dll):
namespace HCInterfaces
{
public interface HomeControlInterface
{
string GetModuleName();
}
}
最后,這是我的Plugin類,輸出plugin.dll:
using HCInterfaces;
using System.Composition;
namespace Plugin2
{
public partial class MainWindow
{
public MainWindow()
{
}
[Export(typeof(HomeControlInterface))]
class BMW : HomeControlInterface
{
public string GetModuleName()
{
return "hännschenklein";
}
}
}
}
問題可能是庫參考不兼容。
也許此鏈接會有所幫助:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.