【问题标题】:Issue with MEF and Prism : A duplicate module with the name {0} has been found by the LoaderMEF 和 Prism 的问题:加载程序发现名称为 {0} 的重复模块
【发布时间】:2013-07-10 12:26:09
【问题描述】:

我正在尝试使用 Prism、MEF 和 WPF 创建一个非常基本的应用程序。我有一个 WPF 应用程序项目,它有一个 Shell.xaml 和 Bootstrapper。 BootStrapper 的代码如下:

public class SimpleMefApplicationBootstrapper : MefBootstrapper
{
    protected override void ConfigureAggregateCatalog()
    {
        //base.ConfigureAggregateCatalog();
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SimpleMefApplicationBootstrapper).Assembly));             
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.HelloModule).Assembly));
        this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.FinishModule).Assembly));
    }        

    protected override DependencyObject CreateShell()
    {
        return this.Container.GetExportedValue<Shell>();
    }

    protected override void InitializeShell()
    {
        //base.InitializeShell();
        Application.Current.MainWindow = (Window)this.Shell;
    }

    protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
    {
        var factory = base.ConfigureDefaultRegionBehaviors();           

        return factory;
    }

在解决方案中,我有另一个类库,它有一个视图文件夹、视图模型文件夹和两个模块。这两个模块绑定到两个视图,以便它们可以用作一个区域。如果我尝试从 botstrapper 仅调用一个模块,但当我同时调用两个模块时,它会完美运行。它给了我错误的详细信息,例如:

Loader 发现了一个名为 FinishModule 的重复模块。

我不明白两个模块是否有不同,那么问题出在哪里。我也尝试为这两个模块更改组装,但没有运气。

有什么想法吗?

【问题讨论】:

    标签: wpf prism mef


    【解决方案1】:

    尝试只使用一个调用:

    public class SimpleMefApplicationBootstrapper : MefBootstrapper
    {
        protected override void ConfigureAggregateCatalog()
        {
            //base.ConfigureAggregateCatalog();
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SimpleMefApplicationBootstrapper).Assembly));   
    
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.HelloModule).Assembly));
          //  this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PrismApp.Module.Hello.FinishModule).Assembly));
        }       
    

    【讨论】:

    • 我太傻了,没想到,但是如果两个不同名称的模块在同一个程序集中,那么我们应该只调用一个吗?是吗?因为它在任何一种情况下都有效。
    • 需要的是您从中派生的程序集,因此取决于您的模块最终所在的位置
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-24
    • 2011-06-08
    相关资源
    最近更新 更多