当前位置: 动力学知识库 > 问答 > 编程问答 >

wpf - Issue with MEF and Prism : A duplicate module with the name {0} has been found by the Loader

问题描述:

I am trying to create a very basic application using Prism, MEF and WPF. I have a WPF application project which has a Shell.xaml and Bootstrapper. Code for BootStrapper is below:

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;

}

In the solution i have another class library which has a View folder, View model Folder and two modules. The two modules are tied to two views so that they can used as a region. It works perfectly if i try to call only one module from botstrapper but not when i call both the modules. It gives me the error details like :

A duplicate module with the name FinishModule has been found by the Loader.

I dont understand if both the modules are having different then what is the problem. I tried changing the assemble also for both the modules but no luck.

Any ideas?

网友答案:

Try using only one call:

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));
    }       
分享给朋友:
您可能感兴趣的文章:
随机阅读: