{"record":{"id":"1d4a0ebc0bb65303","repo":"PrismLibrary/Prism","slug":"invalid-scope-provided-the-current-scope-page-accessor","errorCode":null,"errorMessage":"Invalid Scope provided. The current scope Page Accessor contains '{accessor.Page.GetType().FullName}', expected '{page.GetType().FullName}'.","messagePattern":"Invalid Scope provided\\. The current scope Page Accessor contains '(.+?)', expected '(.+?)'\\.","errorType":"exception","errorClass":"NavigationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/NavigationRegistry.cs","lineNumber":59,"sourceCode":"                }\n                else\n                {\n                    navPage.Navigation.RemovePage(navPage.RootPage);\n                }\n            }\n        }\n\n        if (page.GetContainerProvider() is null)\n            page.SetContainerProvider(container);\n\n        var accessor = container.Resolve<IPageAccessor>();\n        if (accessor.Page is not null && accessor.Page != page)\n        {\n#if DEBUG\n            if (System.Diagnostics.Debugger.IsAttached)\n                System.Diagnostics.Debugger.Break();\n#endif\n            throw new NavigationException($\"Invalid Scope provided. The current scope Page Accessor contains '{accessor.Page.GetType().FullName}', expected '{page.GetType().FullName}'.\", page);\n        }\n\n        accessor.Page ??= page;\n\n        var behaviorFactories = container.Resolve<IEnumerable<IPageBehaviorFactory>>();\n        foreach (var factory in behaviorFactories)\n            factory.ApplyPageBehaviors(page);\n    }\n\n    private static void PreventDefaultRootPage(object sender, NavigationEventArgs e)\n    {\n        if (sender is not NavigationPage navigationPage)\n        {\n            return;\n        }\n\n        if (!navigationPage.RootPage.GetType().Equals(typeof(Page)))\n        {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/NavigationRegistry.cs#L41-L77","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Ensure each navigation creates/uses a scope dedicated to a single Page instance; do not cache or share IPageAccessor across pages.","Change page/ViewModel registrations so pages are transient (or scoped per navigation), not singleton.","Resolve pages through INavigationService/Prism's page creation pipeline instead of directly from the container into a foreign scope.","Remove any custom scope reuse (e.g. storing the scope in a static or singleton service)."],"exampleFix":"// before\nservices.AddSingleton<MainPage>();\n// after\nservices.AddTransient<MainPage>();","handlingStrategy":"validation","validationCode":"if (accessor.Page is not null && accessor.Page.GetType() != expectedPageType)\n    throw new InvalidOperationException(\"Page accessor scope reused across different pages\");","typeGuard":null,"tryCatchPattern":"try { await _navigationService.NavigateAsync(\"MainPage\"); }\ncatch (NavigationException ex) when (ex.Message.Contains(\"Invalid Scope\"))\n{ /* recreate the scope / restart navigation */ }","preventionTips":["Register pages as transient, never singleton","Do not share IPageAccessor or navigation scopes across pages","Create navigation pages through INavigationService, not direct container resolution","Review custom scoped-container registrations after Prism upgrades"],"tags":["navigation","scope","di","prism","xamarin-maui"],"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-16T04:17:20.429Z"}