PrismLibrary/Prism · error · KeyNotFoundException

No view with the name

Error message

No view with the name '{name}' has been registered

What it means

ViewRegistryBase.CreateView looks up a view registration by name via GetRegistration(name); when no view with that name has been registered in the view registry it throws KeyNotFoundException. Prism's view registry must know every view that will be resolved by name for navigation or ViewModelLocator resolution.

Solutions

  1. Register the view with the exact name: use ViewRegistry registration (e.g. in App startup) matching the string passed to CreateView.
  2. Verify the name string for typos and casing against the registration call.
  3. Ensure the view type is also resolvable from the DI container.
  4. Check registration order — the view must be registered before navigation/creation occurs.

Example fix

// before (view never registered)
navigationService.NavigateAsync("DetailsView");
// after
containerRegistry.RegisterForNavigation<DetailsView>("DetailsView");
navigationService.NavigateAsync("DetailsView");
Defensive patterns

Strategy: try-catch

Validate before calling

if (!viewRegistry.IsRegistered(name))
    throw new InvalidOperationException($"View '{name}' must be registered before navigation");

Try / catch

try { var view = registry.CreateView(container, name); }
catch (KeyNotFoundException ex) { logger.LogError(ex, "View '{Name}' not registered", name); }
catch (ViewCreationException ex) { logger.LogError(ex.InnerException, "View creation failed"); }

Prevention

When it happens

Trigger: Calling CreateView(container, name) (directly or via navigation/ViewModelLocator) with a name that was never registered through RegisterView, or with a name whose registration was removed/renamed.

Common situations: Typo in the view name used during navigation (e.g. 'DetailsView' vs 'DetailView'); view registered in a different registry or after navigation runs; DI container lacks the view type registration; platform-specific registration assembly not loaded.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at src/Prism.Core/Mvvm/ViewRegistryBase{TBaseView}.cs:54

    /// <param name="name">The name of the view to retrieve.</param>
    /// <returns>The type of the view, or null if not found.</returns>
    public Type? GetViewType(string name) =>
        GetRegistration(name)?.View;

    /// <summary>
    /// Creates an instance of the specified view using the provided container.
    /// </summary>
    /// <param name="container">The container used to resolve dependencies.</param>
    /// <param name="name">The name of the view to create.</param>
    /// <returns>An instance of the created view.</returns>
    /// <exception cref="KeyNotFoundException">Thrown if the specified view is not registered.</exception>
    /// <exception cref="ViewModelCreationException">Thrown if an error occurs while creating the view model.</exception>
    /// <exception cref="ViewCreationException">Thrown if an error occurs while creating the view.</exception>
    public object? CreateView(IContainerProvider container, string name)
    {
        try
        {
            var registration = GetRegistration(name) ?? throw new KeyNotFoundException($"No view with the name '{name}' has been registered");
            var view = container.Resolve(registration.View) as TBaseView;
            SetNavigationNameProperty(view, registration.Name);

            SetContainerProvider(view, container);
            ConfigureView(view, container);

            if (registration.ViewModel is not null)
                SetViewModelProperty(view, registration.ViewModel);

            Autowire(view);

            return view;
        }
        catch (KeyNotFoundException)
        {
            throw;
        }
        catch (ViewModelCreationException)

View on GitHub (pinned to 358118cd64)