如何在WPF中重新编译空的DirectoryCatalog for MEF

时间:2012-02-10 08:34:38

标签: c# wpf prism mef

我有一个申请这个步骤:

  1. 启动应用程序和ConfigureAggregateCatalog
  2. 登录用户到应用
  3. 将DLL MEF模块下载到名为' Modules'
  4. 的目录
  5. 刷新目录编目 - 存在问题
  6. 我有空目录'模块'下载后我试图加载模块,但没有成功。在线调用DirectoryCatalog.Refresh()

    时出错
      

    System.ComponentModel.Composition.ChangeRejectedException是   用户代码未处理消息=组合保持不变。   由于以下错误,更改被拒绝:   组合产生多个组成错误,有14个根本原因。   根本原因如下。回顾一下   CompositionException.Errors属性以获取更多详细信息。

         

    1)不可重组的进口阻止了出口的变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor   (参数=" downloadedPartCatalogs&#34 ;,   ContractName =" Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer'

         

    2)不可重组的进口阻止了出口的变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader   (ContractName =" Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'

         

    3)不可重组的进口阻止了出口的变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor   (参数=" moduleInitializer&#34 ;,   ContractName =" Microsoft.Practices.Prism.Modularity.IModuleInitializer&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'

         

    4)不可重组进口阻止出口变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader   (ContractName =" Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'

         

    5)不可重组的进口阻止了出口的变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor   (参数=" moduleInitializer&#34 ;,   ContractName =" Microsoft.Practices.Prism.Modularity.IModuleInitializer&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'

         

    6)不可重组的进口阻止了出口的变化   ' GXBilling.ViewsModels.ShellViewModel.ModuleManager   (ContractName =" Microsoft.Practices.Prism.Modularity.IModuleManager&#34)'   部分' GXBilling.ViewsModels.ShellViewModel'。

         

    7)找到多个与约束匹配的导出   '((exportDefinition.ContractName ==   " Microsoft.Practices.Prism.Regions.RegionAdapterMappings")AndAlso   (exportDefinition.Metadata.ContainsKey(" ExportTypeIdentity")AndAlso   " Microsoft.Practices.Prism.Regions.RegionAdapterMappings" .Equals(exportDefinition.Metadata.get_Item(" ExportTypeIdentity"))))'

         

    导致:无法设置导入   ' Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor   (参数=" regionAdapterMappings&#34 ;,   ContractName =" Microsoft.Practices.Prism.Regions.RegionAdapterMappings&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior&#39 ;.   元件:   Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor   (参数=" regionAdapterMappings&#34 ;,   ContractName =" Microsoft.Practices.Prism.Regions.RegionAdapterMappings&#34)    - > Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior    - > AssemblyCatalog(Assembly =" Microsoft.Practices.Prism.MefExtensions,Version = 4.0.0.0,   Culture = neutral,PublicKeyToken = 31bf3856ad364e35")

         

    8)不可重组的进口阻止了出口的变化   ' Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter..ctor   (参数=" regionBehaviorFactory&#34 ;,   ContractName =" Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter'

         

    9)不可重组的进口阻止了出口的变化   ' Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter..ctor   (参数=" regionBehaviorFactory&#34 ;,   ContractName =" Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter'

         

    10)不可重组进口阻止出口变化   ' Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter..ctor   (参数=" regionBehaviorFactory&#34 ;,   ContractName =" Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter'

         

    11)找到了多个与约束匹配的导出   '((exportDefinition.ContractName ==   " Microsoft.Practices.Prism.Regions.IRegionViewRegistry")AndAlso   (exportDefinition.Metadata.ContainsKey(" ExportTypeIdentity")AndAlso   " Microsoft.Practices.Prism.Regions.IRegionViewRegistry" .Equals(exportDefinition.Metadata.get_Item(" ExportTypeIdentity"))))'

         

    导致:无法设置导入   ' Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior..ctor   (参数=" regionViewRegistry&#34 ;,   ContractName =" Microsoft.Practices.Prism.Regions.IRegionViewRegistry&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior&#39 ;.   元件:   Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior..ctor   (参数=" regionViewRegistry&#34 ;,   ContractName =" Microsoft.Practices.Prism.Regions.IRegionViewRegistry&#34)    - > Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior    - > AssemblyCatalog(Assembly =" Microsoft.Practices.Prism.MefExtensions,Version = 4.0.0.0,   Culture = neutral,PublicKeyToken = 31bf3856ad364e35")

         

    12)不可重组的进口阻止了出口的变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor   (参数=" downloadedPartCatalogs&#34 ;,   ContractName =" Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer'

         

    13)不可重组进口阻止出口变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader   (ContractName =" Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'

         

    14)不可重组进口阻止出口变化   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor   (参数=" moduleInitializer&#34 ;,   ContractName =" Microsoft.Practices.Prism.Modularity.IModuleInitializer&#34)'   在一部分   ' Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'

         

    Source = System.ComponentModel.Composition StackTrace:          在System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition)   atomicComposition)          在System.ComponentModel.Composition.Hosting.ExportProvider.OnExportsChanging(ExportsChangeEventArgs)   E)          在System.ComponentModel.Composition.Hosting.CatalogExportProvider.OnCatalogChanging(Object   发件人,ComposablePartCatalogChangeEventArgs e)          在System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnChanging(Object   发件人,ComposablePartCatalogChangeEventArgs e)          在System.ComponentModel.Composition.Hosting.AggregateCatalog.OnChanging(ComposablePartCatalogChangeEventArgs)   E)          在System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnContainedCatalogChanging(Object   发件人,ComposablePartCatalogChangeEventArgs e)          在System.ComponentModel.Composition.Hosting.DirectoryCatalog.OnChanging(ComposablePartCatalogChangeEventArgs)   E)          在System.ComponentModel.Composition.Hosting.DirectoryCatalog.Refresh()          在E:\ Projects中的GXBilling.Bootstrapper.RefreshCatalog()!New!\ GXBilling \ GXBilling \ Bootstrapper.cs:第36行          at GXBilling.ViewsModels.WinLogOnViewModel.FWCore_OnDownloadedModulesCompleted(Object   发件人,EventArgs e)in   E:!\项目新建\ GXBilling \ GXBilling \ ViewsModels \ WinLogOnViewModel.cs:行   168          在BillingCore.FWCore.FWCore_ModuleDownloadedCompleted(Object sender,ModuleDownloadedEventArgs e)中   E:\ Projects!New!\ GXBilling \ BillingCore \ FWCore.cs:第169行          在BillingCore.FWCore.client_DownloadFileCompleted(Object sender,DownloadFileCompletedEventArgs e)中   E:\ Projects!新!\ GXBilling \ BillingCore \ FWCore.cs:第207行          在BillingCore.BillingServiceRef.FileTransferServiceClient.OnDownloadFileCompleted(Object   状态)在E:\ Projects!新!\ GXBilling \ BillingCore \ Service   参考文献\ BillingServiceRef \ Reference.cs:第739行          在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate   callback,Object args,Int32 numArgs)          在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object   source,Delegate方法,Object args,Int32 numArgs,Delegate   catchHandler)          在System.Windows.Threading.DispatcherOperation.InvokeImpl()          在System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object   州)          在System.Threading.ExecutionContext.runTryCode(Object userData)          在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode)   代码,CleanupCode backoutCode,Object userData)          在System.Threading.ExecutionContext.RunInternal(ExecutionContext   executionContext,ContextCallback回调,对象状态)          at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean   ignoreSyncCtx)          在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)          在System.Windows.Threading.DispatcherOperation.Invoke()          在System.Windows.Threading.Dispatcher.ProcessQueue()          在System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean& handling)          在MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean& handling)          在MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)          在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate   callback,Object args,Int32 numArgs)          在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object   source,Delegate方法,Object args,Int32 numArgs,Delegate   catchHandler)          在System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority   优先级,TimeSpan超时,委托方法,对象args,Int32   numArgs)          在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam)          在MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)          在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame   帧)          在System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)          在System.Windows.Window.ShowHelper(Object booleanBox)          在System.Windows.Window.Show()          在System.Windows.Window.ShowDialog()InnerException:

    部分代码由属性Import标记:

    [Import]
    public ShellViewModel ViewModel
    
    [Import(AllowRecomposition = false)]
    public IModuleManager ModuleManager { get; set; }
    
    [Import(typeof(IShell), AllowRecomposition = true)]
    public IShell MainShell { get; set; }
    
    [ImportingConstructor]
    public ModuleImporting(IRegionManager regionManager)
    

    这就是全部。我没有IEnureable或IList等。在代码中。那么问题出在哪里?

2 个答案:

答案 0 :(得分:2)

刷新DirectoryCatalog会触发recomposition。 MEF部件的导入只有在明确标记为这样的情况下才能重新组合,例如:

[ImportMany(typeof(IFoo),AllowRecomposition=true)]
IEnumerable<IFoo> Foos { private get; set; }

如果导入受重组影响,但未标记为AllowRecomposition=true,则会出现错误:“不可重新组合导入阻止导出更改”。

此外,通过构造函数导入根本不支持重构。但是,you can work around this

答案 1 :(得分:0)

每当出现错误时:

  

尝试获取类型实例时发生激活错误   ,键“”“

然后,请检查[Export]中是否已指定<User Control page>我要注入的Region

这是小事但可以在调试中浪费你几个小时!

谢谢! 巴斯