我有以下步骤的应用程序:


启动应用程序和ConfigureAggregateCatalog
登录用户到应用程序
将DLL MEF模块下载到名为“模块”的目录
刷新目录目录-有问题


下载dll后,我尝试加载模块但没有成功,但目录为“ Modules”为空。我在其中调用DirectoryCatalog.Refresh()时出现错误


  System.ComponentModel.Composition.ChangeRejectedException原为
  用户代码未处理Message =组成保持不变。
  更改由于以下错误而被拒绝:
  合成产生了多个合成错误,有14个根本原因。
  根本原因在下面提供。查看
  CompositionException.Errors属性以获取更多详细信息。
  
  1)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor
  (参数=“ downloadedPartCatalogs”,
  ContractName =“ Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer'。
  
  2)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader
  (ContractName =“ Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'。
  
  3)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor
  (参数=“ moduleInitializer”,
  ContractName =“ Microsoft.Practices.Prism.Modularity.IModuleInitializer”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'。
  
  4)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader
  (ContractName =“ Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'。
  
  5)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor
  (参数=“ moduleInitializer”,
  ContractName =“ Microsoft.Practices.Prism.Modularity.IModuleInitializer”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'。
  
  6)不可替代进口阻止出口变化
  'GXBilling.ViewsModels.ShellViewModel.ModuleManager
  (ContractName =“ Microsoft.Practices.Prism.Modularity.IModuleManager”)'
  在“ GXBilling.ViewsModels.ShellViewModel”部分上。
  
  7)发现多个出口与约束条件匹配
  '((exportDefinition.ContractName ==
  “ Microsoft.Practices.Prism.Regions.RegionAdapterMappings”)并且
  (exportDefinition.Metadata.ContainsKey(“ ExportTypeIdentity”)并且还
  “ Microsoft.Practices.Prism.Regions.RegionAdapterMappings” .Equals(exportDefinition.Metadata.get_Item(“ ExportTypeIdentity”)))))'。
  
  结果:无法设置导入
  'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor
  (参数=“ regionAdapterMappings”,
  ContractName =“ Microsoft.Practices.Prism.Regions.RegionAdapterMappings”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior'。
  元件:
  Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor
  (参数=“ regionAdapterMappings”,
  ContractName =“ Microsoft.Practices.Prism.Regions.RegionAdapterMappings”)
  -> Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior
  -> AssemblyCatalog(Assembly =“ Microsoft.Practices.Prism.MefExtensions,Version = 4.0.0.0,
  文化=中性,PublicKeyToken = 31bf3856ad364e35“)
  
  8)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter..ctor
  (参数=“ regionBehaviorFactory”,
  ContractName =“ Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter'。
  
  9)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter..ctor
  (参数=“ regionBehaviorFactory”,
  ContractName =“ Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter'。
  
  10)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter..ctor
  (参数=“ regionBehaviorFactory”,
  ContractName =“ Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter'。
  
  11)发现多个出口与约束条件匹配
  '((exportDefinition.ContractName ==
  “ Microsoft.Practices.Prism.Regions.IRegionViewRegistry”)
  (exportDefinition.Metadata.ContainsKey(“ ExportTypeIdentity”)并且还
  “ Microsoft.Practices.Prism.Regions.IRegionViewRegistry” .Equals(exportDefinition.Metadata.get_Item(“ ExportTypeIdentity”)))))'。
  
  结果:无法设置导入
  'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior..ctor
  (参数=“ regionViewRegistry”,
  ContractName =“ Microsoft.Practices.Prism.Regions.IRegionViewRegistry”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior'。
  元件:
  Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior..ctor
  (参数=“ regionViewRegistry”,
  ContractName =“ Microsoft.Practices.Prism.Regions.IRegionViewRegistry”)
  -> Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior
  -> AssemblyCatalog(Assembly =“ Microsoft.Practices.Prism.MefExtensions,Version = 4.0.0.0,
  文化=中性,PublicKeyToken = 31bf3856ad364e35“)
  
  12)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor
  (参数=“ downloadedPartCatalogs”,
  ContractName =“ Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer'。
  
  13)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader
  (ContractName =“ Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)'
  部分地
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'。
  
  14)不可替代进口阻止出口变化
  'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor
  (参数=“ moduleInitializer”,
  ContractName =“ Microsoft.Practices.Prism.Modularity.IModuleInitializer”)'
  部分地
  '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!New!\ GXBilling \ GXBilling \ Bootstrapper.cs:GX中的GXBilling.Bootstrapper.RefreshCatalog()
         在GXBilling.ViewsModels.WinLogOnViewModel.FWCore_OnDownloadedModulesCompleted(Object
  发送者,EventArgs e)在
  E:\ Projects!New!\ GXBilling \ GXBilling \ ViewsModels \ WinLogOnViewModel.cs:line
  168
         在BillingCore.FWCore.FWCore_ModuleDownloadedCompleted(Object sender,ModuleDownloadedEventArgs e)中
  E:\ Projects!New!\ GXBilling \ BillingCore \ FWCore.cs:line 169
         在BillingCore.FWCore.client_DownloadFileCompleted(Object sender,DownloadFileCompletedEventArgs e)中
  E:\ Projects!New!\ GXBilling \ BillingCore \ FWCore.cs:line 207
         在BillingCore.BillingServiceRef.FileTransferServiceClient.OnDownloadFileCompleted(Object
  状态)在E:\ Projects!New!\ GXBilling \ BillingCore \ Service中
  References \ BillingServiceRef \ Reference.cs:line 739
         在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate
  回调,对象参数,Int32 numArgs)
         在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object
  源,委托方法,对象参数,Int32 numArgs,委托
  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,对象userData)
         在System.Threading.ExecutionContext.RunInternal(ExecutionContext
  executionContext,ContextCallback回调,对象状态)
         在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔值
  ignoreSyncCtx)
         在System.Threading.ExecutionContext.Run(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,布尔值和已处理)
         在MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,布尔值和已处理)
         在MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
         在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate
  回调,对象参数,Int32 numArgs)
         在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object
  源,委托方法,对象参数,Int32 numArgs,委托
  catchHandler)
         在System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority
  优先级,TimeSpan超时,委托方法,对象参数,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等。在代码中。那么问题出在哪里呢?

最佳答案

刷新DirectoryCatalog会触发recomposition。仅当MEF部件上的导入被显式标记为此类时,才可以对其进行重组,例如:

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


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

同样,通过构造函数导入完全不支持重组。但是,you can work around this

关于c# - 如何在WPF中为MEF重新组合空的DirectoryCatalog,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9224904/

10-09 23:44
查看更多