PrismLibrary/Prism · error · DuplicateModuleException
Resources.DuplicatedModule (formatted with duplicateModule)
Error message
Resources.DuplicatedModule (formatted with duplicateModule)
What it means
ValidateUniqueModules throws DuplicateModuleException with Resources.DuplicatedModule when two or more modules in the catalog share the same ModuleName. Module names are the unique keys used for dependency resolution and retrieval, so duplicates make the catalog ambiguous.
Solutions
- Remove the duplicate module registration so each ModuleName appears once.
- Guard additions with a check: if (catalog.Modules.Any(m => m.ModuleName == name)) skip.
- If intentionally reloading, clear or rebuild the catalog instead of re-adding modules.
Example fix
// before
catalog.AddModule(typeof(ModuleA));
if (loadFromConfig) catalog.AddModule(typeof(ModuleA)); // duplicate
// after
catalog.AddModule(typeof(ModuleA));
if (loadFromConfig && !catalog.Modules.Any(m => m.ModuleName == typeof(ModuleA).Name))
catalog.AddModule(typeof(ModuleA)); Defensive patterns
Strategy: validation
Validate before calling
var dupes = modules.GroupBy(m => m.ModuleName).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
if (dupes.Any())
throw new InvalidOperationException($"Duplicate modules: {string.Join(",", dupes)}"); Try / catch
try
{
catalog.Validate();
}
catch (DuplicateModuleException ex)
{
logger.LogError(ex, "Duplicate module '{0}' registered; removing the second registration", ex.Message);
// remove one of the registrations or rebuild the catalog
} Prevention
- Register each module in exactly one place (code OR config, not both)
- Check catalog.Modules before AddModule
- Guard merged-catalog scenarios with a distinct-by-name step
When it happens
Trigger: Adding the same module twice via catalog.AddModule(...), or a module defined both in code and in a config/XAML source merged into the catalog; detected during Validate().
Common situations: Module registered both programmatically and via app.config/XAML; duplicated entries after merging catalogs; copy-paste of module definitions with an unchanged ModuleName.
Related errors
- raiseErrorsChanged
- A dialog's content must be a FrameworkElement
- A dialog's content must be a FrameworkElement
- A dialog's ViewModel must implement the IDialogAware…
- A dialog's ViewModel must implement the IDialogAware…
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/c0c00850913b2f8c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Modularity/ModuleCatalogBase.cs:286
}
}
/// <summary>
/// Makes sure all modules have an Unique name.
/// </summary>
/// <exception cref="DuplicateModuleException">
/// Thrown if the names of one or more modules are not unique.
/// </exception>
protected virtual void ValidateUniqueModules()
{
List<string> moduleNames = 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));
}
}
/// <summary>
/// Ensures that there are no cyclic dependencies.
/// </summary>
protected virtual void ValidateDependencyGraph()
{
SolveDependencies(Modules);
}
/// <summary>
/// Ensures that there are no dependencies between modules on different groups.
/// </summary>
/// <remarks>
/// A groupless module can only depend on other groupless modules.
/// A module within a group can depend on other modules within the same group and/or on groupless modules.
/// </remarks>View on GitHub (pinned to 358118cd64)