{"record":{"id":"b7e3a1fc8ef6c48e","repo":"PrismLibrary/Prism","slug":"viewcreationexception-name-registrytype-ex","errorCode":null,"errorMessage":"ViewCreationException(name, _registryType, ex)","messagePattern":"ViewCreationException\\(name, _registryType, ex\\)","errorType":"exception","errorClass":"ViewCreationException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Mvvm/ViewRegistryBase{TBaseView}.cs","lineNumber":78,"sourceCode":"\n            if (registration.ViewModel is not null)\n                SetViewModelProperty(view, registration.ViewModel);\n\n            Autowire(view);\n\n            return view;\n        }\n        catch (KeyNotFoundException)\n        {\n            throw;\n        }\n        catch (ViewModelCreationException)\n        {\n            throw;\n        }\n        catch (Exception? ex)\n        {\n            throw new ViewCreationException(name, _registryType, ex);\n        }\n    }\n\n    private IEnumerable<Type> GetCandidates(Type viewModelType)\n    {\n        var names = new List<string>\n        {\n            Regex.Replace(viewModelType.Name, @\"ViewModel$\", string.Empty),\n            Regex.Replace(viewModelType.Name, @\"Model$\", string.Empty),\n        };\n\n        if (_registryType == ViewType.Page)\n            names.Add(Regex.Replace(viewModelType.Name, @\"ViewModel$\", \"Page\"));\n        else if (_registryType == ViewType.Region)\n            names.Add(Regex.Replace(viewModelType.Name, @\"ViewModel$\", \"Region\"));\n        else if (_registryType == ViewType.Dialog)\n            names.Add(Regex.Replace(viewModelType.Name, @\"ViewModel$\", \"Dialog\"));\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Mvvm/ViewRegistryBase{TBaseView}.cs#L60-L96","documentation":"CreateView wraps any exception thrown while resolving or configuring a view (other than ViewModelCreationException, which is rethrown as-is) into a ViewCreationException carrying the view name, the registry type, and the inner exception. This gives a uniform failure type for view creation errors.","triggerScenarios":"Any failure during CreateView after registration lookup succeeds: container.Resolve throwing (missing registration for the view type), SetNavigationNameProperty/SetContainerProvider/ConfigureView failing, or the view's constructor throwing — always rethrown as ViewCreationException(name, _registryType, ex).","commonSituations":"View's constructor throws (e.g. uninitialized service, XAML load error); DI container missing a dependency of the view; resolved object cannot be cast to TBaseView (wrong type registered under the name); platform misconfiguration.","solutions":["Inspect the InnerException of ViewCreationException to find the real cause.","Register all dependencies of the view's constructor in the DI container.","Ensure the type registered under the view name derives from the registry's base view type (e.g. Page/ContentControl).","Test view creation at startup (resolve it eagerly) to surface constructor errors early."],"exampleFix":"// before — dependency missing, constructor throws\npublic DetailsView(IMissingService s) { ... }\n// after — register the dependency\nclass App { RegisterTypes(...) { containerRegistry.RegisterSingleton<IMissingService, MissingService>(); containerRegistry.RegisterForNavigation<DetailsView>(); } }","handlingStrategy":"try-catch","validationCode":"// Verify dependencies before creating the view\nforeach (var p in typeof(DetailsView).GetConstructors().First().GetParameters())\n    if (container.Resolve(p.ParameterType) is null)\n        throw new InvalidOperationException($\"Unregistered dependency {p.ParameterType.Name}\");","typeGuard":null,"tryCatchPattern":"try { return registry.CreateView(container, name); }\ncatch (ViewCreationException ex) { logger.LogError(ex.InnerException, \"View '{Name}' creation failed\", name); throw; }","preventionTips":["Always inspect InnerException — it carries the actual failure.","Keep view constructors light; defer work to OnNavigatedTo.","Eagerly resolve views in a smoke test at startup.","Register every constructor dependency in the container."],"tags":["prism","view-creation","exception-wrapping","di"],"backgroundTag":"invalid-state-transition","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"}