我有一个导入IOperation类型列表的工厂类。我收到以下错误,当我尝试解决这个工厂类:MEF导出和导入抽象类型
,导致:
不能激活部分 “Message36Operation”。元素: Message36Operation - > Message36Operation - > DirectoryCatalog ( “\” 路径=)
,导致:
无法获得出口“Message36Operation (ContractName = “一个IOperation”) '从部分 'Message36Operation'。元素: Message36Operation (ContractName = “一个IOperation”) - > Message36Operation - > DirectoryCatalog (PATH = “\”)
结果造成:
无法设置进口 “ OperationsFactory.Operations (ContractName =“IOperation”)'部分 'OperationsFactory'。元素: OperationsFactory.Operations (ContractName = “一个IOperation”) - > OperationsFactory - > AssemblyCatalog (大会= “RmiToODKMessanger,版本= 1.0.0.0, 文化=中立,公钥=空”)
这是我有:
[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引用。插件
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; }
我还没有设法复制你的问题,当我重建这个,它工作正常http://pastebin.com/Z7Nq51b2。你可以把你的抽象类的完整代码。我想你可能会尝试使用'[Import]'实例执行导入吗? –
感谢您的帮助马修。我已经发布了抽象类的代码。我没有进口。也许组装结构是问题? – Lance
排序问题。愚蠢的错误。 TagManager程序集不在/ bin文件夹中,导致BaseRmiOperation cstor崩溃。 cstor开始处的断点永远不会被调用,它总是在线上崩溃以解决OperationFactory。通过回到基础并一次添加一行功能来找出它。谢谢。 – Lance