开发者

MEF: Despite having found and loaded the PRISM modules, app claims they can't be found

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)

MEF: Despite having found and loaded the PRISM modules, app claims they can't be found

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))]
    p开发者_如何学Pythonublic 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?


I haven't done anything with Prism, but is the IRegionManager type exported? Your importing constructor is currently:

[ImportingConstructor]
public NavigationModule(RegionManager regionManager) { }

Whereas, should it be:

[ImportingConstructor]
public NavigationModule(IRegionManager regionManager) { }

Notice the difference between the class RegionManager and the interface IRegionManager 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:

[Export(typeof(ISomething)), PartCreationPolicy(CreationPolicy.NonShared)]

Or, you could use ExportFactory, e.g.:

[Import] ExportFactory<ISomething> SomethingFactory { get; set; }


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:

  1. Version mismatch
  2. Strong name mismatch
  3. LoadContext mismatch
  4. Something else

Fusion Log Viewer might be able to help you pinpoint the error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜