PrismLibrary/Prism · error · NavigationException

Invalid Scope provided. The current scope Page Accessor…

Error message

Invalid Scope provided. The current scope Page Accessor contains '{accessor.Page.GetType().FullName}', expected '{page.GetType().FullName}'.

What it means

Prism keeps one Page Accessor per navigation scope; ConfigurePage asserts that the accessor's cached Page matches the Page being configured. If the accessor already holds a different Page instance, the scope is being reused for the wrong page, so the library throws NavigationException rather than silently attaching behaviors/attributes to the wrong page.

Solutions

  1. Ensure each navigation creates/uses a scope dedicated to a single Page instance; do not cache or share IPageAccessor across pages.
  2. Change page/ViewModel registrations so pages are transient (or scoped per navigation), not singleton.
  3. Resolve pages through INavigationService/Prism's page creation pipeline instead of directly from the container into a foreign scope.
  4. Remove any custom scope reuse (e.g. storing the scope in a static or singleton service).

Example fix

// before
services.AddSingleton<MainPage>();
// after
services.AddTransient<MainPage>();
Defensive patterns

Strategy: validation

Validate before calling

if (accessor.Page is not null && accessor.Page.GetType() != expectedPageType)
    throw new InvalidOperationException("Page accessor scope reused across different pages");

Try / catch

try { await _navigationService.NavigateAsync("MainPage"); }
catch (NavigationException ex) when (ex.Message.Contains("Invalid Scope"))
{ /* recreate the scope / restart navigation */ }

Prevention

When it happens

Trigger: Reusing a scoped container/scope (or a shared IPageAccessor) across two different Page instances; resolving pages with conflicting lifetimes (e.g. a page registered as singleton resolved into a scoped navigation context); manual misuse of IPageAccessor or Prism's scoped navigation APIs.

Common situations: Custom DI registrations where a page or its ViewModel is a singleton shared between scopes; third-party code creating a scope and pushing a different page into it; regression after migrating from Prism 8 (non-scoped) to Prism.Maui (scoped navigation).

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/NavigationRegistry.cs:59

                }
                else
                {
                    navPage.Navigation.RemovePage(navPage.RootPage);
                }
            }
        }

        if (page.GetContainerProvider() is null)
            page.SetContainerProvider(container);

        var accessor = container.Resolve<IPageAccessor>();
        if (accessor.Page is not null && accessor.Page != page)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
                System.Diagnostics.Debugger.Break();
#endif
            throw new NavigationException($"Invalid Scope provided. The current scope Page Accessor contains '{accessor.Page.GetType().FullName}', expected '{page.GetType().FullName}'.", page);
        }

        accessor.Page ??= page;

        var behaviorFactories = container.Resolve<IEnumerable<IPageBehaviorFactory>>();
        foreach (var factory in behaviorFactories)
            factory.ApplyPageBehaviors(page);
    }

    private static void PreventDefaultRootPage(object sender, NavigationEventArgs e)
    {
        if (sender is not NavigationPage navigationPage)
        {
            return;
        }

        if (!navigationPage.RootPage.GetType().Equals(typeof(Page)))
        {

View on GitHub (pinned to 358118cd64)