2016-11-28 8 views
0

MEFを使用してプラグインフレームワークを実現しようとしています。ホストに今DLLロード時のReflectionTypeLoadException

  • ホストプロジェクト(WPF)
  • インタフェース定義プロジェクト(ポータブルクラスライブラリ)
  • プラグインプロジェクト(ポータブルクラスライブラリ)

:私は3つのプロジェクトを持っています、私は(DLLをロードする必要が唯一のクラスを示す)プラグインassemly 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」と部品リストがあることが、わかります

がemtpy ES:これは私のインターフェース定義は(ホストで参照されたDLLを出力する

Exception Screenshot (VS is German)

とプラグインプロジェクト):

namespace HCInterfaces 
{ 
    public interface HomeControlInterface 
    { 
     string GetModuleName(); 
    } 
} 

そして最後に、これは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"; 
      } 
     } 

    } 
} 

答えて

関連する問題