{"record":{"id":"1b398f7c6de61143","repo":"PrismLibrary/Prism","slug":"a-duplicated-module-with-name-0-has-been-found-in-the","errorCode":null,"errorMessage":"A duplicated module with name {0} has been found in the ModuleCatalog.","messagePattern":"A duplicated module with name (.+?) has been found in the ModuleCatalog\\.","errorType":"exception","errorClass":"DuplicateModuleException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Modularity/ModuleManager.cs","lineNumber":72,"sourceCode":"    public void Run()\n    {\n        LoadModulesWhenAvailable();\n    }\n\n    /// <summary>\n    /// Loads and initializes the module in the <see cref=\"IModuleCatalog\"/> with the name <paramref name=\"moduleName\"/>.\n    /// </summary>\n    /// <param name=\"moduleName\">Name of the module requested for initialization.</param>\n    public void LoadModule(string moduleName)\n    {\n        var modules = ModuleCatalog.Modules.Where(m => m.ModuleName == moduleName);\n        if (modules == null || modules.Count() == 0)\n        {\n            throw new ModuleNotFoundException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, moduleName));\n        }\n        else if (modules.Count() > 1)\n        {\n            throw new DuplicateModuleException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.DuplicatedModuleInCatalog, moduleName));\n        }\n\n        var modulesToLoad = ModuleCatalog.CompleteListWithDependencies(modules);\n\n        LoadModules(modulesToLoad);\n    }\n\n    /// <summary>\n    /// Loads the <see cref=\"IModule\"/>'s with <see cref=\"InitializationMode.WhenAvailable\"/>\n    /// </summary>\n    protected void LoadModulesWhenAvailable()\n    {\n        var whenAvailableModules = ModuleCatalog.Modules.Where(m => m.InitializationMode == InitializationMode.WhenAvailable && m.State == ModuleState.NotStarted);\n        if (whenAvailableModules != null)\n            LoadModules(whenAvailableModules);\n    }\n\n    /// <summary>","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Modularity/ModuleManager.cs#L54-L90","documentation":"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.","triggerScenarios":"Registering the same module twice, e.g. calling AddModule<OrderModule>(\"OrderModule\") twice in ConfigureModuleCatalog, or AddModule and AddModule<T> both adding identical names.","commonSituations":"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.","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)."],"exampleFix":"// before\nmoduleCatalog.AddModule<OrderModule>(\"OrderModule\");\nmoduleCatalog.AddModule<OrderModule>(\"OrderModule\"); // duplicate\n// after\nmoduleCatalog.AddModule<OrderModule>(\"OrderModule\"); // once only","handlingStrategy":"validation","validationCode":"var dupes = moduleCatalog.Modules.GroupBy(m => m.ModuleName).Where(g => g.Count() > 1).Select(g => g.Key).ToList();\nif (dupes.Any())\n    throw new InvalidOperationException($\"Duplicate module registrations: {string.Join(\", \", dupes)}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    moduleManager.LoadModule(name);\n}\ncatch (DuplicateModuleException ex)\n{\n    logger.LogError(ex, \"Duplicate module registration for {Module}\", name);\n}","preventionTips":["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."],"tags":["duplicate-module","modularity","catalog"],"backgroundTag":"conflicting-config-options","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}