{"record":{"id":"9ad70f00a6c48247","repo":"PrismLibrary/Prism","slug":"no-view-with-the-viewmodel-viewmodeltype-name-has-been","errorCode":null,"errorMessage":"No View with the ViewModel '{viewModelType.Name}' has been registered","messagePattern":"No View with the ViewModel '(.+?)' has been registered","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Prism.Core/Mvvm/ViewRegistryBase{TBaseView}.cs","lineNumber":157,"sourceCode":"    /// Gets the navigation key associated with the specified view model type, or throws an exception if not found.\n    /// </summary>\n    /// <param name=\"viewModelType\">The type of the view model.</param>\n    /// <returns>The navigation key for the view associated with the view model.</returns>\n    /// <exception cref=\"KeyNotFoundException\">Thrown if no view is registered for the specified view model.</exception>\n    public string GetViewModelNavigationKey(Type viewModelType)\n    {\n        var registration = Registrations.LastOrDefault(x => x.ViewModel == viewModelType);\n        if (registration is not null)\n            return registration.Name;\n\n        var candidates = GetCandidates(viewModelType);\n        registration = Registrations.LastOrDefault(x => candidates.Any(c => c == x.View));\n        if (registration is not null)\n        {\n            return registration.Name;\n        }\n\n        throw new KeyNotFoundException($\"No View with the ViewModel '{viewModelType.Name}' has been registered\");\n    }\n\n    /// <summary>\n    /// Gets a collection of registered views that inherit from or implement the specified base type.\n    /// </summary>\n    /// <param name=\"baseType\">The base type to filter by.</param>\n    /// <returns>A collection of matching view registrations.</returns>\n    public IEnumerable<ViewRegistration> ViewsOfType(Type baseType) =>\n        Registrations.Where(viewRegistration => viewRegistration.View == baseType || baseType.IsAssignableFrom(viewRegistration.View));\n\n    /// <summary>\n    /// Checks if a view is registered with the specified name.\n    /// </summary>\n    /// <param name=\"name\">The name of the view to check.</param>\n    /// <returns>True if the view is registered, false otherwise.</returns>\n    public bool IsRegistered(string name) =>\n        GetRegistration(name) is not null;\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Core/Mvvm/ViewRegistryBase{TBaseView}.cs#L139-L175","documentation":"GetViewModelNavigationKey finds the registered view whose type matches candidates derived from the given ViewModel type and returns the registration name. When no registered view implements/is associated with the ViewModel, it throws KeyNotFoundException. Prism uses this to map a ViewModel type to its view name for navigation.","triggerScenarios":"Calling GetViewModelNavigationKey(typeof(MyViewModel)) (directly or via ViewModelLocator-backed navigation) where no view registered in the registry has MyViewModel as its DataContext/ViewModel type.","commonSituations":"Forgot RegisterForNavigation for the view; ViewModel naming convention mismatch (Prism convention 'MyPage' -> 'MyPageViewModel' broken by renamed types); ViewModel auto-wiring attributes (ViewModelAttribute) missing; view registered only at runtime in another module.","solutions":["Register the view so its ViewModel association exists: containerRegistry.RegisterForNavigation<MyView, MyViewModel>();","Verify Prism's ViewModel naming convention matches (View name = ViewModel name minus 'ViewModel' suffix) or use [ViewModel(typeof(MyViewModel))] on the view.","Check that the module containing the registration is initialized before navigation.","Confirm the ViewModel type passed is the concrete type used at registration (not a base class)."],"exampleFix":"// before\nnavigationService.NavigateAsync<MyViewModel>(); // no view associated\n// after\nclass App { RegisterTypes(...) { containerRegistry.RegisterForNavigation<MyView, MyViewModel>(); } }","handlingStrategy":"validation","validationCode":"var isRegistered = viewRegistryRegistrations.Any(r => r.View == typeof(MyView));\nif (!isRegistered)\n    containerRegistry.RegisterForNavigation<MyView, MyViewModel>();","typeGuard":null,"tryCatchPattern":"try { var key = registry.GetViewModelNavigationKey(typeof(MyViewModel)); }\ncatch (KeyNotFoundException ex) { logger.LogError(ex, \"No view registered for {ViewModel}\", typeof(MyViewModel).Name); }","preventionTips":["Always pair RegisterForNavigation with the ViewModel type argument.","Keep Prism naming conventions intact when renaming views/viewmodels.","Register views in module initialization before any ViewModel-driven navigation."],"tags":["prism","view-registry","viewmodel-locator","navigation"],"backgroundTag":"entity-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"}