MEF:尽管已找到并加载 PRISM 模块,但应用程序声称无法找到它们
我在 PRISM 4.0 应用程序中使用 MEF 来加载模块。 为了确保它们被下载,我使我的 Shell 导入 IPartImportsSatisfiedNotification。然后在 OnImportSatirsfied() 方法中,我可以在调试器中清楚地看到找到了两个模块。 (参见下面的屏幕截图)
但是我不断收到此错误消息:
无法找到类型的模块 'SalesContactManagement.Modules.NavigationModule.NavigationModule, SalesContactManagement.Modules.NavigationModule,版本=1.0.0.0, 导出的模块中“Culture=neutral, PublicToken=null”。制作 确保模块目录中的模块名称与指定的一致 模块类型的 ModuleExportAttribute。
知道为什么 MEF 不起作用吗?非常感谢任何帮助。
更新:
有趣的是,当我将导航模块清空到最低限度时,它工作正常。
[ModuleExport(typeof(NavigationModule))]
public class NavigationModule : IModule
{
private readonly IRegionManager _regionManager;
private readonly ToolbarViewModel _toolbarViewModel;
public void Initialize()
{
}
//[ImportingConstructor]
//public NavigationModule(RegionManager regionManager)
//{
// //_toolbarViewModel = toolbarViewModel;
// _regionManager = regionManager;
//}
}
但是,一旦我将 ImportingContructor 放在那里,对于已经在 Bootstrapper 中注册的类型,它就会失败。有什么想法吗?
I am utilizing MEF in my PRISM 4.0 application to load the modules.
In order to be sure that they are being downloaded I have made my Shell to import IPartImportsSatisfiedNotification. Then within the OnImportSatirsfied() method, I can clearly see in the debugger that the two modules are found. (See screenshot below)
However I keep getting this error message:
Unable to locate the module with type
'SalesContactManagement.Modules.NavigationModule.NavigationModule,
SalesContactManagement.Modules.NavigationModule, Version=1.0.0.0,
Culture=neutral, PublicToken=null' among the exported modules. Make
sure the module name in the module catalog matches that specified on
ModuleExportAttribute for the module type.
Any idea why MEF doesn't work? Any help is highly appreciated.
UPDATE:
Funny enough when I empty the NavigationModule to a minimum it works fine.
[ModuleExport(typeof(NavigationModule))]
public class NavigationModule : IModule
{
private readonly IRegionManager _regionManager;
private readonly ToolbarViewModel _toolbarViewModel;
public void Initialize()
{
}
//[ImportingConstructor]
//public NavigationModule(RegionManager regionManager)
//{
// //_toolbarViewModel = toolbarViewModel;
// _regionManager = regionManager;
//}
}
But as soon as I put an ImportingContructor there, for types that are already registered in Bootstrapper, it fails. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有对 Prism 进行任何操作,但是
IRegionManager
类型是否已导出?您的导入构造函数当前是:而应该是:
请注意作为构造函数参数的类
RegionManager
和接口IRegionManager
之间的区别。编辑:供您发表评论。如果您想每次启动一个新实例,您可以使用
PartCreationPolicyAttribute
:或者,您可以使用
ExportFactory
,例如:I haven't done anything with Prism, but is the
IRegionManager
type exported? Your importing constructor is currently:Whereas, should it be:
Notice the difference between the class
RegionManager
and the interfaceIRegionManager
as the constructor argument.Edit: For your comment. If you want to spin up a new instance each time, you could use either the
PartCreationPolicyAttribute
:Or, you could use
ExportFactory
, e.g.:我建议使用融合日志查看器来查找模块如何加载。当您安装 Visual Studio 时,应该会为您安装 Fusion 日志查看器(您应该只需点击开始 + fusion 即可搜索它)
可能的问题:
Fusion 日志查看器也许可以帮助您查明错误。
I recommend to use fusion log viewer to find how the modules are loaded. Fusion log viewer should be installed for you when you install Visual Studio (you should be able to just hit start + fusion to search for it)
Possible issues:
Fusion Log Viewer might be able to help you pinpoint the error.