如何在WPF中为MEF重新组合空DirectoryCatalog



我有这样一个应用程序:

  1. 启动应用程序并配置aggregatecalog
  2. 登录用户到应用程序
  3. 下载DLL MEF模块到名为' modules '的目录
  4. 刷新目录目录——有问题

下载dll后,我有空目录'Modules',我试图加载模块,但没有成功。在调用DirectoryCatalog.Refresh()

时出现了一个错误

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

1)不可重组的导入阻止了导出的变化"Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer . .男星(参数= " 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 . .男星(参数= " 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 . .男星(参数= " 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 . .男星(参数= " regionAdapterMappings",ContractName ="Microsoft.Practices.Prism.Regions.RegionAdapterMappings")'部分"Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior"。元素:Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior . .男星(参数= " regionAdapterMappings",ContractName = " Microsoft.Practices.Prism.Regions.RegionAdapterMappings")——> Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior——> AssemblyCatalog(装配= " Microsoft.Practices.Prism。= 4.0.0.0 MefExtensions,版本,文化=中立,都必须31 bf3856ad364e35")

8)不可重组的导入阻止了导出的变化"Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter . .男星(参数= " regionBehaviorFactory",ContractName ="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")'部分"Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter"。

9)不可重组的导入阻止了导出的变化"Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter . .男星(参数= " regionBehaviorFactory",ContractName ="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")'部分"Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter"。

10)不可重新组合的导入阻止了导出的更改"Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter . .男星(参数= " 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 . .男星(参数= " regionViewRegistry",ContractName ="Microsoft.Practices.Prism.Regions.IRegionViewRegistry")'部分"Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior"。元素:Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior . .男星(参数= " regionViewRegistry",ContractName = " Microsoft.Practices.Prism.Regions.IRegionViewRegistry")——> Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior——> AssemblyCatalog(装配= " Microsoft.Practices.Prism。= 4.0.0.0 MefExtensions,版本,文化=中立,都必须31 bf3856ad364e35")

12)不可重组的导入阻止了导出的变化"Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer . .男星(参数= " 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 . .男星(参数= " moduleInitializer",ContractName ="Microsoft.Practices.Prism.Modularity.IModuleInitializer")'部分"Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager"。

= System.ComponentModel来源。作文加:System.ComponentModel.Composition.CompositionResult.ThrowOnErrors (AtomicCompositionatomicComposition)System.ComponentModel.Composition.Hosting.ExportProvider.OnExportsChanging (ExportsChangeEventArgse)在System.ComponentModel.Composition.Hosting.CatalogExportProvider.OnCatalogChanging(对象发件人,ComposablePartCatalogChangeEventArgs e)在System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnChanging(对象发件人,ComposablePartCatalogChangeEventArgs e)System.ComponentModel.Composition.Hosting.AggregateCatalog.OnChanging (ComposablePartCatalogChangeEventArgse)在System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnContainedCatalogChanging(对象发件人,ComposablePartCatalogChangeEventArgs e)System.ComponentModel.Composition.Hosting.DirectoryCatalog.OnChanging (ComposablePartCatalogChangeEventArgse)在System.ComponentModel.Composition.Hosting.DirectoryCatalog.Refresh ()GXBillingGXBilling bootstrapper . refreshcatalog () in E:Projects!New!GXBillingGXBillingBootstrapper.cs:行36在GXBilling.ViewsModels.WinLogOnViewModel.FWCore_OnDownloadedModulesCompleted(对象sender, EventArgs e) inE: 项目!新! GXBilling GXBilling ViewsModels WinLogOnViewModel.cs:行168在BillingCore.FWCore。fwcore_moduledownloaddcompleted(对象发送方,moduledownloaddeventargs e) inE: 项目!新! GXBilling BillingCore FWCore.cs: 169行在BillingCore.FWCore。client_downloadfilecomplecompleted(对象发送者,DownloadFileCompletedEventArgs e) inE: 项目!新! GXBilling BillingCore FWCore.cs: 207行在BillingCore.BillingServiceRef.FileTransferServiceClient.OnDownloadFileCompleted(对象E:Projects!新! GXBilling BillingCore 服务引用 BillingServiceRef Reference.cs: 739行System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托返回对象参数,Int32 numArgs)在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象source, Delegate method, Object args, Int32 numArgs, DelegatecatchHandler)在System.Windows.Threading.DispatcherOperation.InvokeImpl ()在System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(对象状态)在System.Threading.ExecutionContext.runTryCode(对象userData)System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup (TryCode代码,清理代码,backoutCode,对象userData)System.Threading.ExecutionContext.RunInternal (ExecutionContextexecutionContext, ContextCallback, callback, Object state)在System.Threading.ExecutionContext。运行ExecutionContext ExecutionContext, ContextCallback callback,对象状态,布尔值ignoreSyncCtx)在System.Threading.ExecutionContext。运行(ExecutionContext, ExecutionContext, ContextCallback, callback, Object state)在System.Windows.Threading.DispatcherOperation.Invoke ()在System.Windows.Threading.Dispatcher.ProcessQueue ()在System.Windows.Threading.Dispatcher。windprochook (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&处理)在MS.Win32.HwndWrapper。windproc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, boolean &;处理)在MS.Win32.HwndSubclass。DispatcherCallbackOperation(对象o)System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托返回对象参数,Int32 numArgs)在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象source, Delegate method, Object args, Int32 numArgs, DelegatecatchHandler)System.Windows.Threading.Dispatcher.InvokeImpl (DispatcherPriority优先级,超时时间,委托方法,对象参数,Int32numArgs)在MS.Win32.HwndSubclass。SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)在MS.Win32.UnsafeNativeMethods.DispatchMessage (MSG&味精)System.Windows.Threading.Dispatcher.PushFrameImpl (DispatcherFrame框架)在System.Windows.Threading.Dispatcher。PushFrame (DispatcherFrame框架)在System.Windows.Window。booleanBox ShowHelper(对象)在System.Windows.Window.Show ()at system . windows . windows . 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)

。我没有iureable或IList等。在代码中。那么问题在哪里呢?

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

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

如果一个导入受到重组的影响,但它没有被标记为AllowRecomposition=true,那么你会得到一个错误:"Change in exports prevent by non-recomposable import"。

同样,通过构造函数导入根本不支持重构。但是,您可以解决这个问题。

每当出现如下错误:

"尝试获取类型的实例时发生激活错误。,键" ">

然后检查Region中要注入的<User Control page>中是否指定了[Export]属性

这是一件小事,但会浪费你的调试时间!

谢谢!低音部

最新更新