首页 文章

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

提问于
浏览
2

我有这个步骤的应用程序:

  • 启动应用程序和ConfigureAggregateCatalog

  • 登录用户到应用程序

  • 将DLL MEF模块下载到名为'Modules'的目录

  • 刷新目录目录 - there is a problem

我有空目录'模块'后下载DLL我试图加载模块但没有成功 . 我在线上有一个错误,我称之为DirectoryCatalog.Refresh()

System.ComponentModel.Composition.ChangeRejectedException未被用户代码处理Message =组合保持不变 . 由于以下错误,更改被拒绝:组合产生多个组合错误,有14个根本原因 . 根本原因如下 . 查看CompositionException.Errors属性以获取更多详细信息 . 1)由不可重组的导入阻止的导出变化'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer..ctor(Parameter =“downloadedPartCatalogs”,ContractName =“Microsoft.Practices.Prism.MefExtensions.Modularity.DownloadedPartCatalogCollection”)'部分'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer' . 2)部分'Microsoft.Practices上的不可重组导入'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader(ContractName =“Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)'阻止了导出的变化 . Prism.MefExtensions.Modularity.MefModuleManager” . 3)由不可重组的导入'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor(Parameter =“moduleInitializer”,ContractName =“Microsoft.Practices.Prism.Modularity.IModuleInitializer”)'阻止出口的变化'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager' . 4)部分'Microsoft.Practices'中不可重组的导入'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader(ContractName =“Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)'阻止了导出的变化 . Prism.MefExtensions.Modularity.MefModuleManager” . 5)由不可重组的导入'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor(Parameter =“moduleInitializer”,ContractName =“Microsoft.Practices.Prism.Modularity.IModuleInitializer”)'阻止出口的变化'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager' . 6)部分'GXBilling.ViewsModels.ShellViewModel'上的不可重组导入'GXBilling.ViewsModels.ShellViewModel.ModuleManager(ContractName =“Microsoft.Practices.Prism.Modularity.IModuleManager”)'阻止了导出的变化 . 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(Parameter =“regionAdapterMappings”,ContractName =“Microsoft.Practices.Prism.Regions.RegionAdapterMappings”)'''部分'微软 . Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior” . 元素: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(Parameter =“regionBehaviorFactory”,ContractName =“Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory”)'on'Microsoft.Practices.Prism.MefExtensions.Regions.MefSelectorRegionAdapter' . 9)由不可重组的导入'Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter..ctor(Parameter =“regionBehaviorFactory”,ContractName =“Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory”)阻止出口的变化'Microsoft.Practices.Prism.MefExtensions.Regions.MefItemsControlRegionAdapter' . 10)由非重组导入'Microsoft.Practices.Prism.MefExtensions.Regions.MefContentControlRegionAdapter..ctor(Parameter =“regionBehaviorFactory”,ContractName =“Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory”)阻止的出口变化'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(Parameter =“regionViewRegistry”,ContractName =“Microsoft.Practices.Prism.Regions.IRegionViewRegistry”)''部分'微软 . Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior” . 元素: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阻止的导出更改 . 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上的非重组导入'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.mefFileModuleTypeLoader(ContractName =“Microsoft.Practices.Prism.MefExtensions.Modularity.MefFileModuleTypeLoader”)'阻止了导出的变化 . Prism.MefExtensions.Modularity.MefModuleManager” . 14)由不可重组的导入'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager..ctor(Parameter =“moduleInitializer”,ContractName =“Microsoft.Practices.Prism.Modularity.IModuleInitializer”)'阻止出口的变化'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager' . Source = System.ComponentModel.Composition StackTrace:位于System.ComponentModel.Composition.Holting.CatalogExportProvider的System.ComponentModel.Composition.Hosting.ExportProvider.OnExportsChanging(ExportsChangeEventArgs e)中的System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition atomicComposition) . OnCatalogChanging(Object sender,ComposablePartCatalogChangeEventArgs e)位于System.ComponentModel.Composition的System.ComponentModel.Composition.Hosting.AggregateCatalog.OnChanging(ComposablePartCatalogChangeEventArgs e)的System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnChanging(Object sender,ComposablePartCatalogChangeEventArgs e) . 在System.ComponentModel.Composition.Hosting.DirectoryCatalog.Refresh的System.ComponentModel.Composition.Hosting.DirectoryCatalog.OnChanging(ComposablePartCatalogChangeEventArgs e)中的Hosting.ComposablePartCatalogCollection.OnContainedCatalogChanging(Object sender,ComposablePartCatalogChangeEventArgs e) ()在E:\ Projects中的GXBilling.Bootstrapper.RefreshCatalog()!New!\ GXBilling \ GXBilling \ Bootstrapper.cs:E:\ Projects中GXBilling.ViewsModels.WinLogOnViewModel.FWCore_OnDownloadedModulesCompleted(Object sender,EventArgs e)的第36行!新的!\ GXBilling \ GXBilling \ ViewsModels \ WinLogOnViewModel.cs:BillingCore中的BillingCore.FWCore.FWCore_ModuleDownloadedCompleted(对象发送者,ModuleDownloadedEventArgs e)中的第168行:E!\ Projects!New!\ GXBilling \ BillingCore \ FWCore.cs:BillingCore中的第169行 . E:\ Projects中的FWCore.client_DownloadFileCompleted(Object sender,DownloadFileCompletedEventArgs e)!在E:\ Projects中的BillingCore.BillingServiceRef.FileTransferServiceClient.OnDownloadFileCompleted(对象状态)中的新!\ GXBilling \ BillingCore \ FWCore.cs:第207行!新! GXBilling \ BillingCore \ Service References \ BillingServiceRef \ Reference.cs:System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,Object args,Int32 numArgs)中的第739行,位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源) ,System.Whows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)中的System.Windows.Threading.DispatcherOperation.InvokeImpl()处于System.Threading.ExecutionContext.runTryCode(Object userData)的,Delegate方法,Object args,Int32 numArgs,Delegate catchHandler) )在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode,对象的UserData)在System.Threading.ExecutionContext.RunInternal(的ExecutionContext的ExecutionContext,ContextCallback回调,对象状态)在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext System.Windows.Threading.Dispatcher.ProcessQueue上System.Windows.Threading.DispatcherOperation.Invoke()的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态),ContextCallback回调,对象状态,布尔值ignoreSyncCtx) ()在System.Windows.Threading.Dispatcher.WndProcHook(IntPtr在MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)的MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&handling)的hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&handling) System.Windows上的MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate方法,Object args,Int32 numArgs,Delegate catchHandler)上的System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,Object args,Int32 numArgs) .Threading.Dispatcher.InvokeImpl(DispatcherPriority priority,TimeSpan timeout,Delegate方法,Object args,Int32 numArgs)位于MS.Win32.UnsafeNativeMethods的MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam) . 在System.Windows上System.Windows.Window.ShowHelper(Object booleanBox)的System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)的System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame框架)中的DispatchMessage(MSG和msg) . System.Windows.Window.ShowDialog()中的Window.Show()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 回答

  • 2

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

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

    如果导入受重构影响,但未标记为 AllowRecomposition=true ,则会出现错误:"Change in exports prevented by non-recomposable import" .

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

  • 0

    每当出现错误时:

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

    然后请检查 <User Control page> 中是否指定 [Export] 属性,我们将在 Region 中注入 .

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

    谢谢!巴斯

相关问题