mefx 未列出进口商
我有一个基于 MEF 的模块化应用程序,它开始无法导入类。在调试过程中,我一直使用 mefx
工具来尝试找出核心问题。简而言之,我的所有 [Export]
声明似乎都是正确的,但 Import
或 ImportMany
属性似乎都没有得到正确处理。
希望这对我来说是一个简单的错误,但该应用程序直到最近才工作。
这是我编写的一个非常简短的测试应用程序以及相应的 mefx
输出。
using System.ComponentModel.Composition;
namespace ClassLibrary1
{
public class Class1
{
[Import]
public Class2 myclass;
}
[Export]
public class Class2
{
}
}
我希望mexf
输出
> mefx /file:ClassLibrary1.dll /parts
ClassLibrary1.Class2
> mefx /file:ClassLibrary1.dll /exports
ClassLibrary1.Class2
> mefx /file:ClassLibrary1.dll /imports
[blank]
将 Class1
列为导入器。建议?
I have a MEF-based modular app that has started to fail to import classes. In the course of debugging, I've been using the mefx
tools to try to track down the core issue. In short, all of my [Export]
declarations appear to be correct, but none of the Import
or ImportMany
attributes seem to be processed correctly.
Hopefully this is a simple mistake on my part, but the application was working until recently.
Here is a very short test application I've written along with the corresponding mefx
output.
using System.ComponentModel.Composition;
namespace ClassLibrary1
{
public class Class1
{
[Import]
public Class2 myclass;
}
[Export]
public class Class2
{
}
}
And the mexf
output
> mefx /file:ClassLibrary1.dll /parts
ClassLibrary1.Class2
> mefx /file:ClassLibrary1.dll /exports
ClassLibrary1.Class2
> mefx /file:ClassLibrary1.dll /imports
[blank]
I would have expected Class1
to be listed as an importer. Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能导入 MEF 未引用的类。
尝试:
您也可以在构造函数中导入它:
另外,使用 ServiceLocator 获取 Class1(不要使用“new”关键字)。
You cannot import in a class not referenced by MEF.
Try:
You could also import it in the constructor:
Also, use the ServiceLocator to get Class1 (don't use the "new" keyword).