{"record":{"id":"517b55f04862440d","repo":"PrismLibrary/Prism","slug":"the-scoped-provider-has-already-been-assigned-to-another","errorCode":null,"errorMessage":"The Scoped Provider has already been assigned to another page. Expected: '{page.GetType().FullName}' - Found: '{accessor.Page.GetType().FullName}'.","messagePattern":"The Scoped Provider has already been assigned to another page\\. Expected: '(.+?)' - Found: '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Xaml/Navigation.cs","lineNumber":46,"sourceCode":"    {\n        if (bindable is not Page page || oldValue == newValue)\n        {\n            return;\n        }\n\n        if (oldValue != null && newValue is null && oldValue is IScopedProvider oldProvider)\n        {\n            oldProvider.Dispose();\n            return;\n        }\n\n        if (newValue != null && newValue is IScopedProvider scopedProvider)\n        {\n            var accessor = scopedProvider.Resolve<IPageAccessor>();\n            if (accessor.Page is null)\n                accessor.Page = page;\n            else if (accessor.Page != page)\n                throw new InvalidOperationException($\"The Scoped Provider has already been assigned to another page. Expected: '{page.GetType().FullName}' - Found: '{accessor.Page.GetType().FullName}'.\");\n\n            scopedProvider.IsAttached = true;\n        }\n    }\n\n    /// <summary>\n    /// Provides bindable CanNavigate Bindable Property\n    /// </summary>\n    public static readonly BindableProperty CanNavigateProperty =\n        BindableProperty.CreateAttached(\"CanNavigate\",\n            typeof(bool),\n            typeof(Navigation),\n            true,\n            propertyChanged: OnCanNavigatePropertyChanged);\n\n    internal static readonly BindableProperty RaiseCanExecuteChangedInternalProperty =\n        BindableProperty.CreateAttached(\"RaiseCanExecuteChangedInternal\",\n            typeof(Action),","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Xaml/Navigation.cs#L28-L64","documentation":"Prism's Navigation attached property (Navigation.Scope) validates that an IScopedProvider is bound to exactly one page. OnNavigationScopeChanged resolves IPageAccessor from the scoped provider; if the provider's Page is already set to a different page, it throws InvalidOperationException, because sharing one scoped service provider across pages would leak scoped state.","triggerScenarios":"Setting Navigation.ScopeProperty with an IScopedProvider whose IPageAccessor.Page already holds a different page — typically reusing the same scoped provider instance across two pages or assigning the scope property twice with different pages.","commonSituations":"Manually assigning Navigation.Scope in XAML/code with a provider created for another page; creating one scope in a parent page and attaching it to a pushed child page; navigation page reuse where the provider wasn't reset.","solutions":["Create a new IScopedProvider per page; never reuse one across pages.","Only set Navigation.Scope with the provider created for that exact page (e.g. via Prism's navigation pipeline).","If re-navigating, clear/rebuild the scope instead of reassigning it.","Check for duplicate Scope assignments in XAML and code-behind."],"exampleFix":"// before: reusing parent's scope on child page\nchildPage.SetValue(Navigation.ScopeProperty, parentScope);\n// after: let Prism create the scope per page, or create a fresh one\nvar childScope = scopeFactory.CreateScopedProvider(childPage);\nchildPage.SetValue(Navigation.ScopeProperty, childScope);","handlingStrategy":"validation","validationCode":"if (scopedProvider.Resolve<IPageAccessor>() is { } accessor && accessor.Page is not null && accessor.Page != page)\n    throw new InvalidOperationException(\"Scoped provider already bound to a different page\");","typeGuard":"if (newValue is IScopedProvider sp && sp.Resolve<IPageAccessor>().Page is null) { /* safe to attach */ }","tryCatchPattern":"try\n{\n    Navigation.SetScope(page, scopedProvider);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Scoped Provider\"))\n{\n    logger.LogError(ex, \"Scoped provider reused across pages\");\n}","preventionTips":["Let Prism's navigation pipeline create the scope per page; avoid manual Scope assignment.","Never share one IScopedProvider between pages.","Audit XAML/code-behind for duplicate Navigation.Scope assignments.","Rebuild (not reassign) scopes on page reuse or re-navigation."],"tags":["prism","maui","navigation","scoped-services","invalid-operation"],"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"}