Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MEF:尽管已经找到并加载了PRISM模块,但app声称它们可以';找不到_C#_.net_Prism_Mef - Fatal编程技术网

C# MEF:尽管已经找到并加载了PRISM模块,但app声称它们可以';找不到

C# MEF:尽管已经找到并加载了PRISM模块,但app声称它们可以';找不到,c#,.net,prism,mef,C#,.net,Prism,Mef,我在PRISM 4.0应用程序中使用MEF加载模块。 为了确保它们被下载,我已经制作了Shell以导入iPartimportsAssetFiedNotification。然后在onimportsatirsified()方法中,我可以在调试器中清楚地看到找到了这两个模块。(见下面的屏幕截图) 但是,我不断收到以下错误消息: 找不到类型为的模块 'SalesContactManagement.Modules.NavigationModule.NavigationModule, SalesConta

我在PRISM 4.0应用程序中使用MEF加载模块。 为了确保它们被下载,我已经制作了Shell以导入iPartimportsAssetFiedNotification。然后在onimportsatirsified()方法中,我可以在调试器中清楚地看到找到了这两个模块。(见下面的屏幕截图)

但是,我不断收到以下错误消息:

找不到类型为的模块 'SalesContactManagement.Modules.NavigationModule.NavigationModule, SalesContactManagement.Modules.NavigationModule,版本=1.0.0.0, 导出模块中的Culture=neutral,PublicToken=null。制作 确保模块目录中的模块名称与上指定的名称匹配 模块类型的ModuleExportAttribute

知道MEF为什么不起作用吗?非常感谢您的帮助

更新:

有趣的是,当我将NavigationModule清空到最小值时,它工作正常

 [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;
        //}
}
但一旦我在那里放置了导入构造函数,对于已经在Bootstrapper中注册的类型,它就会失败。有什么想法吗?

我建议使用查找模块的加载方式。当您安装Visual Studio时,应该为您安装Fusion日志查看器(您应该能够点击start+Fusion来搜索它)

可能的问题:

  • 版本不匹配
  • 强名称不匹配
  • 加载上下文不匹配
  • 别的

  • Fusion Log Viewer可能可以帮助您查明错误。

    我没有对Prism做任何操作,但是是否导出了
    IRegionManager
    类型?您的导入构造函数当前为:

    [ImportingConstructor]
    public NavigationModule(RegionManager regionManager) { }
    
    鉴于,应为:

    [ImportingConstructor]
    public NavigationModule(IRegionManager regionManager) { }
    
    注意类
    RegionManager
    和接口
    IRegionManager
    作为构造函数参数之间的区别

    编辑:供您评论。如果希望每次启动一个新实例,可以使用
    PartCreationPolicyAttribute

    [Export(typeof(ISomething)), PartCreationPolicy(CreationPolicy.NonShared)]
    
    或者,您可以使用
    ExportFactory
    ,例如:

    [Import] ExportFactory<ISomething> SomethingFactory { get; set; }
    
    [Import]ExportFactory SomethingFactory{get;set;}
    
    谢谢你的提示。我已经启动了,但是前三个按钮变灰了。我必须在上面拖放日志文件吗?您必须以管理员身份运行它。还请注意,使用后必须将其设置为其他设置,否则fusion loader将继续记录(影响性能并占用磁盘空间)。谢谢Matthew,我终于解决了这个问题。调试MEF比Unity困难得多。但这很有趣。这是一条被拒绝的进口线,因此它拒绝了包括模块在内的整个链。这让我相信模块没有找到。我喜欢我。让我看看。我还有一个问题,你知道我是如何强迫MEF获得一个新实例的吗?我不断得到相同的实例,即使它被定义为非共享…也许我应该把这变成一个新问题。。。