Topics: Prism v2 - WPF 3.5
May 22, 2009 at 5:59 AM

When I add a different module with DirectoryModuleCatalog, I got a exception of DuplicateModuleException in the following line,

        protected virtual void ValidateUniqueModules()
            List<string> moduleNames = this.Modules.Select(m => m.ModuleName).ToList();

            string duplicateModule = moduleNames.FirstOrDefault(
                m => moduleNames.Count(m2 => m2 == m) > 1);

            if (duplicateModule != null)
                throw new DuplicateModuleException(duplicateModule, String.Format(CultureInfo.CurrentCulture, Resources.DuplicatedModule, duplicateModule));

The reason is that I have two modules like these,

==== test1.dll ===
namespace FirstProject
  public class Module1 : ... {}

==== test2.dll ===
namespace SecondProject
  public class Module1 : ... {}

Despite of the fact each namespaces are different, DirectoryModuleCatalog add a module type with a "Class Name" Key, which make an exception in the process of validation.
There is a workaround if you have source codes with your project.

==== CreateModuleInfo method in DirectoryModuleCatalog.Desktop.cs ====

// moduleName == "Module1"
// type.FullName == "FirstProject.Module1" or "SecondProject.Module1"

//                ModuleInfo moduleInfo = new ModuleInfo(moduleName, type.AssemblyQualifiedName)
                ModuleInfo moduleInfo = new ModuleInfo(type.FullName, type.AssemblyQualifiedName)
                                                InitializationMode =
                                                        ? InitializationMode.OnDemand
                                                        : InitializationMode.WhenAvailable,
                                                Ref = type.Assembly.CodeBase,

I think, it also has to reflect into Composite WPF source codes.

May 22, 2009 at 6:52 PM

Hi Seong Tae Jeong,


The approach you have taken is one possible workaround. However, have in mind that if you have dependencies between modules the name of these modules will be the full name and not just the name of the class that implements IModule.


In the case you have access to the source code, perhaps you could take a different approach that does not modify the CALs source code:

1.       Change the name of the module class so they are different.

2.       Add a ModuleName property to your module classes, with the specific name you want the module to be named. In your case it could be: “FirstProject.Module1” and “SecondProject.Module1”. The module loader will use this property and the names will be different.


Please let me know if this helps.


Damian Schenkelman