{"record":{"id":"dd3d2db5b85f30b6","repo":"PrismLibrary/Prism","slug":"properties-resources-failedtogettype-string-format-with","errorCode":null,"errorMessage":"Properties.Resources.FailedToGetType (string.Format with typeName)","messagePattern":"Properties\\.Resources\\.FailedToGetType \\(string\\.Format with typeName\\)","errorType":"exception","errorClass":"ModuleInitializeException","httpStatus":null,"severity":"critical","filePath":"src/Wpf/Prism.Wpf/Modularity/ModuleInitializer.cs","lineNumber":110,"sourceCode":"        protected virtual IModule CreateModule(IModuleInfo moduleInfo)\n        {\n            if (moduleInfo == null)\n                throw new ArgumentNullException(nameof(moduleInfo));\n\n            return CreateModule(moduleInfo.ModuleType);\n        }\n\n        /// <summary>\n        /// Uses the container to resolve a new <see cref=\"IModule\"/> by specifying its <see cref=\"Type\"/>.\n        /// </summary>\n        /// <param name=\"typeName\">The type name to resolve. This type must implement <see cref=\"IModule\"/>.</param>\n        /// <returns>A new instance of <paramref name=\"typeName\"/>.</returns>\n        protected virtual IModule CreateModule(string typeName)\n        {\n            Type moduleType = Type.GetType(typeName);\n            if (moduleType == null)\n            {\n                throw new ModuleInitializeException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.FailedToGetType, typeName));\n            }\n\n            return (IModule)_containerExtension.Resolve(moduleType);\n        }\n    }\n}\n","sourceCodeStart":92,"sourceCodeEnd":117,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Modularity/ModuleInitializer.cs#L92-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use typeof(SomeModule).AssemblyQualifiedName when building the ModuleInfo instead of a hand-typed string.","Verify the module assembly is referenced by the startup project (CopyLocal true) so it is in the bin folder at load time.","Check the exact spelling: namespace + class name must match the target type, e.g. 'MyApp.Modules.FooModule, MyApp.Modules'.","If loading by simple name, ensure the assembly is already loaded into the AppDomain, or resolve it via Assembly.Load before Type.GetType."],"exampleFix":"// before\nnew ModuleInfo { ModuleName = \"Foo\", ModuleType = \"MyApp.FooModl, MyApp\" };\n// after\nnew ModuleInfo { ModuleName = \"Foo\", ModuleType = typeof(MyApp.FooModule).AssemblyQualifiedName };","handlingStrategy":"validation","validationCode":"var moduleType = Type.GetType(moduleTypeString);\nif (moduleType == null)\n    throw new InvalidOperationException($\"Module type '{moduleTypeString}' could not be resolved. Check spelling and that the assembly is loaded.\");","typeGuard":"bool IsResolvableType(string typeName) => !string.IsNullOrWhiteSpace(typeName) && Type.GetType(typeName, throwOnError: false) != null;","tryCatchPattern":"try\n{\n    moduleManager.Run();\n}\ncatch (ModuleInitializeException ex)\n{\n    logger.LogError(ex, \"Module type could not be resolved: {0}\", ex.Message);\n}","preventionTips":["Use typeof(T).AssemblyQualifiedName for ModuleType strings","Ensure module assemblies are referenced and copied to output","Verify module type strings after renaming classes/namespaces"],"tags":["wpf","modularity","reflection","type-resolution"],"backgroundTag":"class-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"}