簡體   English   中英

DLL加載時ReflectionTypeLoadException

[英]ReflectionTypeLoadException on DLL load

我正在嘗試使用MEF實現插件框架。 我有3個項目:

  • 主機項目(WPF)
  • 接口定義項目(便攜式類庫)
  • 插件項目(便攜式類庫)

現在在主機中,我嘗試加載插件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”,零件清單是空的:

異常截圖(VS是德語)

這是我的接口定義(輸出主機和插件項目中引用的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";
            }
        }

    }
}

問題可能是庫參考不兼容。
也許此鏈接會有所幫助:

.NET 4.5和Windows Store PCL的MEF 2合成

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM