{"record":{"id":"ce6bdbf1d9242ce6","repo":"dotnet/maui","slug":"poptorootasync-is-not-supported-globally-on-androi","errorCode":null,"errorMessage":"PopToRootAsync is not supported globally on Android, please use a NavigationPage.","messagePattern":"PopToRootAsync is not supported globally on Android, please use a NavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/AppCompat/Platform.cs","lineNumber":182,"sourceCode":"\t\t\t\t\tmodalContainer.Dispose();\n\t\t\t\t\tsource.TrySetResult(modal);\n\t\t\t\t\tCurrentPageController?.SendAppearing();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tUpdateAccessibilityImportance(CurrentPageController as Page, ImportantForAccessibility.Auto, true);\n\n\t\t\treturn source.Task;\n\t\t}\n\n\t\tTask INavigation.PopToRootAsync()\n\t\t{\n\t\t\treturn ((INavigation)this).PopToRootAsync(true);\n\t\t}\n\n\t\tTask INavigation.PopToRootAsync(bool animated)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"PopToRootAsync is not supported globally on Android, please use a NavigationPage.\");\n\t\t}\n\n\t\tTask INavigation.PushAsync(Page root)\n\t\t{\n\t\t\treturn ((INavigation)this).PushAsync(root, true);\n\t\t}\n\n\t\tTask INavigation.PushAsync(Page root, bool animated)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"PushAsync is not supported globally on Android, please use a NavigationPage.\");\n\t\t}\n\n\t\tTask INavigation.PushModalAsync(Page modal)\n\t\t{\n\t\t\treturn ((INavigation)this).PushModalAsync(modal, true);\n\t\t}\n\n\t\tasync Task INavigation.PushModalAsync(Page modal, bool animated)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/AppCompat/Platform.cs#L164-L200","documentation":"Thrown by the Platform class's explicit INavigation.PopToRootAsync(bool) implementation. On Android, popping to the root of the page stack is a NavigationPage operation; the global platform only handles modals. The guard routes developers to NavigationPage.","triggerScenarios":"Calling await Application.Current.MainPage.Navigation.PopToRootAsync() on Android without a NavigationPage root. The platform INavigation is used instead of a NavigationPage's, triggering the throw.","commonSituations":"Cross-platform shared code calling PopToRootAsync unconditionally. App structured with a TabbedPage or single ContentPage root instead of a NavigationPage.","solutions":["Ensure the root is a NavigationPage so PopToRootAsync is handled by the NavigationPage renderer.","Use modal pop (PopModalAsync) if the intent is to dismiss a modal, not to clear a page stack.","Refactor navigation calls to obtain Navigation from the enclosing NavigationPage."],"exampleFix":"// before\nawait page.Navigation.PopToRootAsync();\n\n// after\nif (NavigationPage.GetNavigationPage(page) is NavigationPage np)\n    await np.Navigation.PopToRootAsync();\nelse\n    await page.Navigation.PopModalAsync();","handlingStrategy":"validation","validationCode":"// Only call PopToRootAsync when a NavigationPage hosts the page.\nif (NavigationPage.GetNavigationPage(currentPage) is NavigationPage np)\n    await np.Navigation.PopToRootAsync();\nelse\n    await currentPage.Navigation.PopModalAsync();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the root is a NavigationPage for apps needing pop-to-root behavior on Android.","Provide a navigation helper that detects the host type and chooses the correct API.","Test navigation flows on Android early, not just on iOS."],"tags":["android","navigation","poptorootasync","navigationpage","platform"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}