{"record":{"id":"c0c00850913b2f8c","repo":"PrismLibrary/Prism","slug":"resources-duplicatedmodule-formatted-with-duplicatemodule","errorCode":null,"errorMessage":"Resources.DuplicatedModule (formatted with duplicateModule)","messagePattern":"Resources\\.DuplicatedModule \\(formatted with duplicateModule\\)","errorType":"exception","errorClass":"DuplicateModuleException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Modularity/ModuleCatalogBase.cs","lineNumber":286,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// Makes sure all modules have an Unique name.\n        /// </summary>\n        /// <exception cref=\"DuplicateModuleException\">\n        /// Thrown if the names of one or more modules are not unique.\n        /// </exception>\n        protected virtual void ValidateUniqueModules()\n        {\n            List<string> moduleNames = Modules.Select(m => m.ModuleName).ToList();\n\n            string duplicateModule = moduleNames.FirstOrDefault(\n                m => moduleNames.Count(m2 => m2 == m) > 1);\n\n            if (duplicateModule != null)\n            {\n                throw new DuplicateModuleException(duplicateModule, string.Format(CultureInfo.CurrentCulture, Resources.DuplicatedModule, duplicateModule));\n            }\n        }\n\n        /// <summary>\n        /// Ensures that there are no cyclic dependencies.\n        /// </summary>\n        protected virtual void ValidateDependencyGraph()\n        {\n            SolveDependencies(Modules);\n        }\n\n        /// <summary>\n        /// Ensures that there are no dependencies between modules on different groups.\n        /// </summary>\n        /// <remarks>\n        /// A groupless module can only depend on other groupless modules.\n        /// A module within a group can depend on other modules within the same group and/or on groupless modules.\n        /// </remarks>","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Modularity/ModuleCatalogBase.cs#L268-L304","documentation":"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.","triggerScenarios":"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().","commonSituations":"Module registered both programmatically and via app.config/XAML; duplicated entries after merging catalogs; copy-paste of module definitions with an unchanged ModuleName.","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."],"exampleFix":"// before\ncatalog.AddModule(typeof(ModuleA));\nif (loadFromConfig) catalog.AddModule(typeof(ModuleA)); // duplicate\n// after\ncatalog.AddModule(typeof(ModuleA));\nif (loadFromConfig && !catalog.Modules.Any(m => m.ModuleName == typeof(ModuleA).Name))\n    catalog.AddModule(typeof(ModuleA));","handlingStrategy":"validation","validationCode":"var dupes = modules.GroupBy(m => m.ModuleName).Where(g => g.Count() > 1).Select(g => g.Key).ToList();\nif (dupes.Any())\n    throw new InvalidOperationException($\"Duplicate modules: {string.Join(\",\", dupes)}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    catalog.Validate();\n}\ncatch (DuplicateModuleException ex)\n{\n    logger.LogError(ex, \"Duplicate module '{0}' registered; removing the second registration\", ex.Message);\n    // remove one of the registrations or rebuild the catalog\n}","preventionTips":["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"],"tags":["duplicate-module","validation","prism"],"backgroundTag":"duplicate-module-registration","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}