MEF导出和导入抽象类型

时间:2011-11-28 13:39:55

标签: mef

我有一个工厂类,用于导入IOperation类型列表。当我尝试解决工厂类时出现以下错误:

导致:

  

无法激活部分   'Message36Operation'。元件:   Message36Operation - >   Message36Operation - > DirectoryCatalog   (路径= “\”)

导致:

  

无法导出'Message36Operation   (ContractName =“IOperation”)'来自部分   'Message36Operation'。元件:   Message36Operation   (ContractName =“IOperation”) - >   Message36Operation - > DirectoryCatalog   (路径= “\”)

导致:

  

无法设置导入   “OperationsFactory.Operations   (ContractName =“IOperation”)'部分   'OperationsFactory'。元件:   OperationsFactory.Operations   (ContractName =“IOperation”) - >   OperationsFactory - > AssemblyCatalog   (Assembly =“RmiToODKMessanger,Version = 1.0.0.0,   Culture = neutral,PublicKeyToken = null“)

这就是我所拥有的:

[Export(typeof(OperationsFactory))]
public class OperationsFactory
{
    [ImportMany(typeof(IOperation))]
    private IEnumerable<IOperation> Operations { get; set; }
 }

public interface IOperation
{

}

public abstract class BaseRmiOperation : IOperation
{

}

[Export(typeof(IOperation))]
public class Message36Operation : BaseRmiOperation, IOperation
{

}

抛出异常将尝试解析工厂的实例。

如果删除抽象类,我可以使用它。

任何想法,

谢谢,

**更新:

以下是BaseRmiOperation类。我在cstor中实例化了一些类,就是这样。

我之前忘了提到应用程序的结构。

  • CG.App:包含MEF的OperationsFactory和bootstrapper类。
  • CG.Plugins:包含各种IOperation实现,如Message36Operation和BaseRmiOperation抽象类
  • CG.Common:包含IOperation接口。 CG.App和CG.Plugins
  • 都引用了这个程序集

CG.App.Bootstrapper类从bin / plugins加载插件。

public abstract class BaseRmiOperation : IOperation
{

    protected SettingsManager _settingsManager;
    protected RmiMessenger _messenager;
    protected ILogger _logger;
    protected TagManager _tagManager;

    protected Environments _rmiEnvironment;
    protected string _msgSource;
    protected string _emp_id;

    public BaseRmiOperation()
    {

        this._settingsManager = new SettingsManager();
        this._messenager = new RmiMessenger(null, null);
        this._tagManager = new TagManager(); // pass ILogger 
        //this._logger = logger;

        // pulls the rmi_env and a few other settings from
        // winCC.
        PopulateRmiSettings();

    }


    public abstract ExitCodes Execute(object[] data);

    public abstract string Description { get;  }

    public abstract string Alias { get;  }

1 个答案:

答案 0 :(得分:1)

对问题进行排序。愚蠢的错误。 TagManager程序集不存在于/ bin文件夹中,导致BaseRmiOperation cstor崩溃。从未调用过cstor开头的断点,它总是在行上崩溃以解析OperationFactory。通过回归基础知识并一次添加一行功能来计算出来。感谢。

相关问题