gpt4 book ai didi

c# - 如何在 WPF 中为 MEF 重组空的 DirectoryCatalog

转载 作者:太空宇宙 更新时间:2023-11-03 11:26:18 27 4
gpt4 key购买 nike

我有一个包含以下步骤的应用程序:

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

下载 dll 后我有一个空目录“Modules” 我尝试加载模块但没有成功。我调用 DirectoryCatalog.Refresh() 的行出错

System.ComponentModel.Composition.ChangeRejectedException was unhandled by user code Message=The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced multiple composition errors, with 14 root causes. The root causes are provided below. Review the CompositionException.Errors property for more detailed information.

1) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor (Parameter="downloadedPartCatalogs", ContractName="Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer'.

2) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader (ContractName="Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.

3) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor (Parameter="moduleInitializer", ContractName="Microsoft.Practices.Prism.Modularity.IModuleInitializer")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.

4) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader (ContractName="Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.

5) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor (Parameter="moduleInitializer", ContractName="Microsoft.Practices.Prism.Modularity.IModuleInitializer")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.

6) Change in exports prevented by non-recomposable import 'GXBilling.ViewsModels.ShellViewModel.ModuleManager (ContractName="Microsoft.Practices.Prism.Modularity.IModuleManager")' on part 'GXBilling.ViewsModels.ShellViewModel'.

7) More than one export was found that matches the constraint '((exportDefinition.ContractName == "Microsoft.Practices.Prism.Regions.RegionAdapterMappings") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "Microsoft.Practices.Prism.Regions.RegionAdapterMappings".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor (Parameter="regionAdapterMappings", ContractName="Microsoft.Practices.Prism.Regions.RegionAdapterMappings")' on part 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior'. Element: Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor (Parameter="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, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

8) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter..ctor (Parameter="regionBehaviorFactory", ContractName="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")' on part 'Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter'.

9) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter..ctor (Parameter="regionBehaviorFactory", ContractName="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")' on part 'Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter'.

10) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter..ctor (Parameter="regionBehaviorFactory", ContractName="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")' on part 'Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter'.

11) More than one export was found that matches the constraint '((exportDefinition.ContractName == "Microsoft.Practices.Prism.Regions.IRegionViewRegistry") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "Microsoft.Practices.Prism.Regions.IRegionViewRegistry".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior..ctor (Parameter="regionViewRegistry", ContractName="Microsoft.Practices.Prism.Regions.IRegionViewRegistry")' on part 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior'. Element: Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior..ctor (Parameter="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, Culture=neutral, PublicKeyToken=31bf3856ad364e35")

12) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor (Parameter="downloadedPartCatalogs", ContractName="Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer'.

13) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader (ContractName="Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.

14) Change in exports prevented by non-recomposable import 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor (Parameter="moduleInitializer", ContractName="Microsoft.Practices.Prism.Modularity.IModuleInitializer")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.

Source=System.ComponentModel.Composition StackTrace: at System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition atomicComposition) at System.ComponentModel.Composition.Hosting.ExportProvider.OnExportsChanging(ExportsChangeEventArgs e) at System.ComponentModel.Composition.Hosting.CatalogExportProvider.OnCatalogChanging(Object sender, ComposablePartCatalogChangeEventArgs e) at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnChanging(Object sender, ComposablePartCatalogChangeEventArgs e) at System.ComponentModel.Composition.Hosting.AggregateCatalog.OnChanging(ComposablePartCatalogChangeEventArgs e) at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnContainedCatalogChanging(Object sender, ComposablePartCatalogChangeEventArgs e) at System.ComponentModel.Composition.Hosting.DirectoryCatalog.OnChanging(ComposablePartCatalogChangeEventArgs e) at System.ComponentModel.Composition.Hosting.DirectoryCatalog.Refresh() at GXBilling.Bootstrapper.RefreshCatalog() in E:\Projects!New!\GXBilling\GXBilling\Bootstrapper.cs:line 36 at GXBilling.ViewsModels.WinLogOnViewModel.FWCore_OnDownloadedModulesCompleted(Object sender, EventArgs e) in E:\Projects!New!\GXBilling\GXBilling\ViewsModels\WinLogOnViewModel.cs:line 168 at BillingCore.FWCore.FWCore_ModuleDownloadedCompleted(Object sender, ModuleDownloadedEventArgs e) in E:\Projects!New!\GXBilling\BillingCore\FWCore.cs:line 169 at BillingCore.FWCore.client_DownloadFileCompleted(Object sender, DownloadFileCompletedEventArgs e) in E:\Projects!New!\GXBilling\BillingCore\FWCore.cs:line 207 at BillingCore.BillingServiceRef.FileTransferServiceClient.OnDownloadFileCompleted(Object state) in E:\Projects!New!\GXBilling\BillingCore\Service References\BillingServiceRef\Reference.cs:line 739 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Window.ShowHelper(Object booleanBox) at System.Windows.Window.Show() at 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com