PrismLibrary/Prism · error · DuplicateModuleException
A duplicated module with name
Error message
A duplicated module with name {0} has been found in the ModuleCatalog. What it means
When LoadModule finds more than one IModuleInfo with the same ModuleName in the catalog, it cannot know which to initialize and throws DuplicateModuleException with 'A duplicated module with name {0} has been found in the ModuleCatalog.' Prism enforces unique module names within the catalog.
Solutions
- Remove the duplicate AddModule call so each ModuleName is registered exactly once.
- Guard against double registration: if (!catalog.Modules.Any(m => m.ModuleName == name)) catalog.AddModule<T>(name);
- Audit for ConfigureModuleCatalog being invoked multiple times (check for base override calls or repeated App initialization).
Example fix
// before
moduleCatalog.AddModule<OrderModule>("OrderModule");
moduleCatalog.AddModule<OrderModule>("OrderModule"); // duplicate
// after
moduleCatalog.AddModule<OrderModule>("OrderModule"); // once only Defensive patterns
Strategy: validation
Validate before calling
var dupes = moduleCatalog.Modules.GroupBy(m => m.ModuleName).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
if (dupes.Any())
throw new InvalidOperationException($"Duplicate module registrations: {string.Join(", ", dupes)}"); Try / catch
try
{
moduleManager.LoadModule(name);
}
catch (DuplicateModuleException ex)
{
logger.LogError(ex, "Duplicate module registration for {Module}", name);
} Prevention
- Register each module exactly once in ConfigureModuleCatalog.
- Add a startup unit test asserting unique ModuleName values.
- Avoid calling base.ConfigureModuleCatalog and adding the same modules again.
When it happens
Trigger: Registering the same module twice, e.g. calling AddModule<OrderModule>("OrderModule") twice in ConfigureModuleCatalog, or AddModule and AddModule<T> both adding identical names.
Common situations: Copy-paste duplication in ConfigureModuleCatalog; registration code executed twice (e.g. App class re-instantiated or ConfigureModuleCatalog overridden and base called); conditional registration branches that both run.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- Module was not found in the catalog.
- Value cannot be null. (Parameter 'name')
- Value cannot be null. (Parameter 'dependsOn')
- Value cannot be null. (Parameter 'type')
- Module Reference Location is not supported in Maui
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/1b398f7c6de61143.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Modularity/ModuleManager.cs:72
public void Run()
{
LoadModulesWhenAvailable();
}
/// <summary>
/// Loads and initializes the module in the <see cref="IModuleCatalog"/> with the name <paramref name="moduleName"/>.
/// </summary>
/// <param name="moduleName">Name of the module requested for initialization.</param>
public void LoadModule(string moduleName)
{
var modules = ModuleCatalog.Modules.Where(m => m.ModuleName == moduleName);
if (modules == null || modules.Count() == 0)
{
throw new ModuleNotFoundException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, moduleName));
}
else if (modules.Count() > 1)
{
throw new DuplicateModuleException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.DuplicatedModuleInCatalog, moduleName));
}
var modulesToLoad = ModuleCatalog.CompleteListWithDependencies(modules);
LoadModules(modulesToLoad);
}
/// <summary>
/// Loads the <see cref="IModule"/>'s with <see cref="InitializationMode.WhenAvailable"/>
/// </summary>
protected void LoadModulesWhenAvailable()
{
var whenAvailableModules = ModuleCatalog.Modules.Where(m => m.InitializationMode == InitializationMode.WhenAvailable && m.State == ModuleState.NotStarted);
if (whenAvailableModules != null)
LoadModules(whenAvailableModules);
}
/// <summary>View on GitHub (pinned to 358118cd64)