{"record":{"id":"a6b2068a56f3a094","repo":"PrismLibrary/Prism","slug":"resources-modulenotfound-string-format-with-modulename","errorCode":null,"errorMessage":"Resources.ModuleNotFound (string.Format with moduleName)","messagePattern":"Resources\\.ModuleNotFound \\(string\\.Format with moduleName\\)","errorType":"exception","errorClass":"ModuleNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Modularity/ModuleManager.cs","lineNumber":81,"sourceCode":"        /// </summary>\n        public void Run()\n        {\n            ModuleCatalog.Initialize();\n\n            LoadModulesWhenAvailable();\n        }\n\n\n        /// <summary>\n        /// Loads and initializes the module on 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 module = ModuleCatalog.Modules.Where(m => m.ModuleName == moduleName);\n            if (module == null || module.Count() != 1)\n            {\n                throw new ModuleNotFoundException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, moduleName));\n            }\n\n            var modulesToLoad = ModuleCatalog.CompleteListWithDependencies(module);\n\n            LoadModuleTypes(modulesToLoad);\n        }\n\n        /// <summary>\n        /// Checks if the module needs to be retrieved before it's initialized.\n        /// </summary>\n        /// <param name=\"moduleInfo\">Module that is being checked if needs retrieval.</param>\n        /// <returns></returns>\n        protected virtual bool ModuleNeedsRetrieval(IModuleInfo moduleInfo)\n        {\n            if (moduleInfo == null)\n                throw new ArgumentNullException(nameof(moduleInfo));\n\n            if (moduleInfo.State == ModuleState.NotStarted)","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Modularity/ModuleManager.cs#L63-L99","documentation":"ModuleManager.LoadModule looks up the module catalog for exactly one ModuleInfo whose ModuleName matches; when none or more than one match, it throws ModuleNotFoundException with Resources.ModuleNotFound. The catalog is the source of truth for registered modules, so this error means the requested name was never registered (or is duplicated).","triggerScenarios":"Calling moduleManager.LoadModule(\"Foo\") where \"Foo\" is not a ModuleName in the IModuleCatalog, the name is misspelled, or duplicate ModuleInfos share the same ModuleName (Count() != 1 branch).","commonSituations":"Request-on-demand modules loaded by string name from config/URI; renaming a module's ModuleName in the catalog but not at the LoadModule call site; accidentally adding the same module twice via AddModule; using the class name instead of the registered ModuleName.","solutions":["Confirm the exact ModuleName string used in AddModule/catalog matches the LoadModule argument (it is the ModuleName, not the type name).","Inspect ModuleCatalog.Modules at a breakpoint or log to list registered names and fix the spelling.","Remove duplicate AddModule calls registering the same ModuleName.","Centralize module names in constants so catalog registration and LoadModule use one source."],"exampleFix":"// before\nmoduleManager.LoadModule(\"FooModule\"); // registered as \"Foo\"\n// after\nmoduleManager.LoadModule(\"Foo\"); // matches ModuleInfo.ModuleName","handlingStrategy":"validation","validationCode":"var matches = moduleCatalog.Modules.Where(m => m.ModuleName == moduleName).ToList();\nif (matches.Count != 1)\n    throw new InvalidOperationException($\"Module '{moduleName}' not found (or duplicated) in catalog. Registered: {string.Join(\", \", moduleCatalog.Modules.Select(m => m.ModuleName))}\");","typeGuard":"bool IsRegisteredModule(IModuleCatalog catalog, string name) =>\n    catalog.Modules.Count(m => string.Equals(m.ModuleName, name, StringComparison.Ordinal)) == 1;","tryCatchPattern":"try\n{\n    moduleManager.LoadModule(moduleName);\n}\ncatch (ModuleNotFoundException ex)\n{\n    logger.LogError(ex, \"Unknown module '{0}' — check catalog registration\", moduleName);\n}","preventionTips":["Define module names as constants shared by registration and LoadModule call sites","Log the list of registered ModuleNames at startup","Avoid registering the same ModuleName twice"],"tags":["wpf","modularity","module-catalog","lookup-failed"],"backgroundTag":"record-not-found","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"}