【发布时间】:2012-01-07 22:59:55
【问题描述】:
我有一个导入 IOperation 类型列表的工厂类。尝试解析工厂类时出现以下错误:
导致:
无法激活部分 'Message36 操作'。元素: Message36 操作 --> Message36Operation --> DirectoryCatalog (路径=".\")
导致:
无法导出'Message36Operation (ContractName="IOOperation")' 来自部分 'Message36 操作'。元素: Message36操作 (ContractName="IOOperation") --> Message36Operation --> DirectoryCatalog (路径=".\")
导致:
无法设置导入 'OperationsFactory.Operations (ContractName="IOOperation")' 部分 '操作工厂'。元素: OperationsFactory.Operations (ContractName="IOOperation") --> OperationsFactory --> AssemblyCatalog (Assembly="RmiToODKMessanger, 版本=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 和引导程序类。
- 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; }
【问题讨论】:
-
我无法复制您的问题,当我重建它时,它可以正常工作pastebin.com/Z7Nq51b2。你能把你的抽象类的完整代码放在哪里吗?我想您可能会尝试使用
[Import]实例对其执行导入? -
感谢马修的帮助。我已经发布了抽象类的代码。我没有进口。也许装配结构是问题?
-
对问题进行了排序。愚蠢的错误。 /bin 文件夹中不存在 TagManager 程序集,导致 BaseRmiOperation cstor 崩溃。从未调用 cstor 开头的断点,它总是在解决 OperationFactory 的行上崩溃。通过回到基础并一次添加一行功能来解决这个问题。谢谢。
标签: mef