PrismLibrary/Prism · critical · ModuleInitializeException

Properties.Resources.FailedToGetType (string.Format with…

Error message

Properties.Resources.FailedToGetType (string.Format with typeName)

What it means

ModuleInitializer.CreateModule calls Type.GetType(typeName) and throws ModuleInitializeException when the type cannot be resolved. This means the string passed (from xaml module catalog or configuration) does not name a loadable Type in any currently loaded assembly. Prism wraps the failure so the module-loading pipeline reports a single, consistent exception type.

Solutions

  1. Use typeof(SomeModule).AssemblyQualifiedName when building the ModuleInfo instead of a hand-typed string.
  2. Verify the module assembly is referenced by the startup project (CopyLocal true) so it is in the bin folder at load time.
  3. Check the exact spelling: namespace + class name must match the target type, e.g. 'MyApp.Modules.FooModule, MyApp.Modules'.
  4. If loading by simple name, ensure the assembly is already loaded into the AppDomain, or resolve it via Assembly.Load before Type.GetType.

Example fix

// before
new ModuleInfo { ModuleName = "Foo", ModuleType = "MyApp.FooModl, MyApp" };
// after
new ModuleInfo { ModuleName = "Foo", ModuleType = typeof(MyApp.FooModule).AssemblyQualifiedName };
Defensive patterns

Strategy: validation

Validate before calling

var moduleType = Type.GetType(moduleTypeString);
if (moduleType == null)
    throw new InvalidOperationException($"Module type '{moduleTypeString}' could not be resolved. Check spelling and that the assembly is loaded.");

Type guard

bool IsResolvableType(string typeName) => !string.IsNullOrWhiteSpace(typeName) && Type.GetType(typeName, throwOnError: false) != null;

Try / catch

try
{
    moduleManager.Run();
}
catch (ModuleInitializeException ex)
{
    logger.LogError(ex, "Module type could not be resolved: {0}", ex.Message);
}

Prevention

When it happens

Trigger: Calling CreateModule(typeName) (directly or via ModuleInitializer.Initialize when the module catalog loads) with a type name that Type.GetType cannot resolve: wrong namespace/class spelling, missing 'AssemblyQualifiedName' portion when the assembly is not already loaded, or the module assembly not being referenced/copied to the output.

Common situations: ModuleInfo.ModuleType strings hand-edited in App.xaml/csharpxaml ModuleCatalog or app.config; renamed module class or namespace without updating the catalog; module assembly not referenced by the shell project so it is never copied to bin; case-sensitivity mismatches.

Related errors


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

Appendix: source

Thrown at src/Wpf/Prism.Wpf/Modularity/ModuleInitializer.cs:110

        protected virtual IModule CreateModule(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
                throw new ArgumentNullException(nameof(moduleInfo));

            return CreateModule(moduleInfo.ModuleType);
        }

        /// <summary>
        /// Uses the container to resolve a new <see cref="IModule"/> by specifying its <see cref="Type"/>.
        /// </summary>
        /// <param name="typeName">The type name to resolve. This type must implement <see cref="IModule"/>.</param>
        /// <returns>A new instance of <paramref name="typeName"/>.</returns>
        protected virtual IModule CreateModule(string typeName)
        {
            Type moduleType = Type.GetType(typeName);
            if (moduleType == null)
            {
                throw new ModuleInitializeException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.FailedToGetType, typeName));
            }

            return (IModule)_containerExtension.Resolve(moduleType);
        }
    }
}

View on GitHub (pinned to 358118cd64)