【问题标题】:WPF: how to reload AggregateCatalog in Prism + MEF?WPF:如何在 Prism + MEF 中重新加载 AggregateCatalog?
【发布时间】:2015-02-18 06:06:20
【问题描述】:

如何正确重新加载 Prism 的 AggregateCatalog ?当文件更改时,我需要 Prism 重新加载其目录,但它一直给我这个错误:

未处理的类型异常 'System.ComponentModel.Composition.ChangeRejectedException' 发生 在 System.ComponentModel.Composition.dll 中

这里是引导程序 sn-p。清除 AggregateCatalog 时失败。

class Bootstrapper : MefBootstrapper
{
    private readonly FileSystemWatcher _fileWatcher;

    public Bootstrapper()
    {
        _fileWatcher = new FileSystemWatcher(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Modules"));
        _fileWatcher.Created += fileWatcher_Changed;
        _fileWatcher.Changed += fileWatcher_Changed;
        _fileWatcher.Deleted += fileWatcher_Changed;
        _fileWatcher.Renamed += fileWatcher_Changed;
        _fileWatcher.EnableRaisingEvents = true;
    }

    private void fileWatcher_Changed(object sender, FileSystemEventArgs e)
    {
        this.AggregateCatalog.Catalogs.Clear(); //It fails here!
        ConfigureAggregateCatalog();
        ConfigureContainer();
    }

【问题讨论】:

  • ChangeRejectedException.Errors 列表中包含哪些错误?
  • 构图保持不变。由于以下错误,更改被拒绝: 合成产生了多个合成错误,有 2 个根本原因。下面提供了根本原因。查看 CompositionException.Errors 属性以获取更多详细信息。
  • 1) 不可重组的导入 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior..ctor (Parameter="regionAdapterMappings", ContractName="Microsoft.Practices. Prism.Regions.RegionAdapterMappings")' 在部分 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefDelayedRegionCreationBehavior'。
  • 2) 不可重组的导入 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior..ctor (Parameter="regionViewRegistry", ContractName="Microsoft.Practices. Prism.Regions.IRegionViewRegistry")' 在部分 'Microsoft.Practices.Prism.MefExtensions.Regions.Behaviors.MefAutoPopulateRegionBehavior'。
  • 默认情况下,导入不允许重组(参见:msdn.microsoft.com/en-us/library/…)。至少,您应该允许它重建您的目录。

标签: c# wpf prism mef


【解决方案1】:

这是不可能的。 当应用程序启动时,模块目录在初始化期间构建,此后不再使用甚至销毁。 如此动态地,无需重新启动应用程序,就无法使用 prism 添加模块。

【讨论】:

    猜你喜欢
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    相关资源
    最近更新 更多