如何在WPF中为MEF重新组合空的DirectoryCatalog [英] How to recomposit empty DirectoryCatalog for MEF in WPF

查看:96
本文介绍了如何在WPF中为MEF重新组合空的DirectoryCatalog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行以下步骤的应用程序:

I have an application with these step:

  1. 启动应用程序和ConfigureAggregateCatalog
  2. 将用户登录到应用
  3. 将DLL MEF模块下载到名为模块"的目录中
  4. 刷新目录目录-有问题
  1. startup application and ConfigureAggregateCatalog
  2. logon user to app
  3. download DLL MEF modules to directory called 'Modules'
  4. refresh directory catalog -- there is a problem

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

I have empty directory 'Modules' after download dll i tried to load modules but without succes. There is an error on line where I called DirectoryCatalog.Refresh()

System.ComponentModel.Composition.ChangeRejectedException原为 用户代码未处理Message =组成保持不变. 更改由于以下错误而被拒绝: 合成产生了多个合成错误,有14个根本原因. 根本原因在下面提供.查看 CompositionException.Errors属性以获取更多详细信息.

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor (参数="downloadedPartCatalogs", ContractName ="Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection")' 部分地 "Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer".

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader (ContractName ="Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader")' 部分地 "Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager".

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor (参数="moduleInitializer", ContractName ="Microsoft.Practices.Prism.Modularity.IModuleInitializer")' 部分地 "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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader (ContractName ="Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader")' 部分地 "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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor (参数="moduleInitializer", ContractName ="Microsoft.Practices.Prism.Modularity.IModuleInitializer")' 部分地 "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)不可替代进口阻止出口变化 'GXBilling.ViewsModels.ShellViewModel.ModuleManager (ContractName ="Microsoft.Practices.Prism.Modularity.IModuleManager")' 在"GXBilling.ViewsModels.ShellViewModel"部分.

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)找到多个与约束匹配的出口 '(((exportDefinition.ContractName == "Microsoft.Practices.Prism.Regions.RegionAdapterMappings")并且 (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity")并且还 "Microsoft.Practices.Prism.Regions.RegionAdapterMappings" .Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))))'.

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"))))'.

结果:无法设置导入 '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, Culture = neutral,PublicKeyToken = 31bf3856ad364e35)

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter..ctor (参数="regionBehaviorFactory", ContractName ="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")' 部分地 "Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter".

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter..ctor (参数="regionBehaviorFactory", ContractName ="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")' 部分地 "Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter".

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter..ctor (参数="regionBehaviorFactory", ContractName ="Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory")' 部分地 "Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter".

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)找到不止一个符合条件的出口 '(((exportDefinition.ContractName == "Microsoft.Practices.Prism.Regions.IRegionViewRegistry") (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity")并且还 "Microsoft.Practices.Prism.Regions.IRegionViewRegistry" .Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))))'.

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"))))'.

结果:无法设置导入 '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, Culture = neutral,PublicKeyToken = 31bf3856ad364e35)

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)不可替代进口阻止出口变化 'Microsoft.Primices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor (参数="downloadedPartCatalogs", ContractName ="Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection")' 部分地 "Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer".

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader (ContractName ="Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader")' 部分地 "Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager".

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)不可替代进口阻止出口变化 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor (参数="moduleInitializer", ContractName ="Microsoft.Practices.Prism.Modularity.IModuleInitializer")' 部分地 "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: 在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 executeContext,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,Boolean&处理) 在MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&处理) 在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:

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标记:

There is parts of code marked by attribute 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等.在代码中.那哪里出问题了?

That's all. I have not IEnureable or IList or etc. In code. So where is problem?

推荐答案

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

Refreshing the DirectoryCatalog triggers a recomposition. An import on a MEF part can only be recomposed if it is explicitly marked as such, for example like this:

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

如果导入受重组影响,但未标记为AllowRecomposition=true,则会出现错误:不可重组的导入阻止了出口的变化".

If an import is affected by the recomposition, but it isn't marked with AllowRecomposition=true, then you get an error: "Change in exports prevented by non-recomposable import".

此外,通过构造函数导入完全不支持重组.但是,您可以解决此问题.

Also, imports via a constructor don't support recomposition at all. However, you can work around this.

这篇关于如何在WPF中为MEF重新组合空的DirectoryCatalog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆