PrismLibrary/Prism · error · ModuleNotFoundException

Resources.ModuleNotFound (string.Format with moduleName)

Error message

Resources.ModuleNotFound (string.Format with moduleName)

What it means

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).

Solutions

  1. Confirm the exact ModuleName string used in AddModule/catalog matches the LoadModule argument (it is the ModuleName, not the type name).
  2. Inspect ModuleCatalog.Modules at a breakpoint or log to list registered names and fix the spelling.
  3. Remove duplicate AddModule calls registering the same ModuleName.
  4. Centralize module names in constants so catalog registration and LoadModule use one source.

Example fix

// before
moduleManager.LoadModule("FooModule"); // registered as "Foo"
// after
moduleManager.LoadModule("Foo"); // matches ModuleInfo.ModuleName
Defensive patterns

Strategy: validation

Validate before calling

var matches = moduleCatalog.Modules.Where(m => m.ModuleName == moduleName).ToList();
if (matches.Count != 1)
    throw new InvalidOperationException($"Module '{moduleName}' not found (or duplicated) in catalog. Registered: {string.Join(", ", moduleCatalog.Modules.Select(m => m.ModuleName))}");

Type guard

bool IsRegisteredModule(IModuleCatalog catalog, string name) =>
    catalog.Modules.Count(m => string.Equals(m.ModuleName, name, StringComparison.Ordinal)) == 1;

Try / catch

try
{
    moduleManager.LoadModule(moduleName);
}
catch (ModuleNotFoundException ex)
{
    logger.LogError(ex, "Unknown module '{0}' — check catalog registration", moduleName);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/a6b2068a56f3a094. Report an issue: GitHub.

Appendix: source

Thrown at src/Wpf/Prism.Wpf/Modularity/ModuleManager.cs:81

        /// </summary>
        public void Run()
        {
            ModuleCatalog.Initialize();

            LoadModulesWhenAvailable();
        }


        /// <summary>
        /// Loads and initializes the module on 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 module = ModuleCatalog.Modules.Where(m => m.ModuleName == moduleName);
            if (module == null || module.Count() != 1)
            {
                throw new ModuleNotFoundException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, moduleName));
            }

            var modulesToLoad = ModuleCatalog.CompleteListWithDependencies(module);

            LoadModuleTypes(modulesToLoad);
        }

        /// <summary>
        /// Checks if the module needs to be retrieved before it's initialized.
        /// </summary>
        /// <param name="moduleInfo">Module that is being checked if needs retrieval.</param>
        /// <returns></returns>
        protected virtual bool ModuleNeedsRetrieval(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
                throw new ArgumentNullException(nameof(moduleInfo));

            if (moduleInfo.State == ModuleState.NotStarted)

View on GitHub (pinned to 358118cd64)