{"record":{"id":"d7e8412b05bff243","repo":"dotnet/maui","slug":"parentingviewcontroller-parent-could-not-be-found-d7e841","errorCode":null,"errorMessage":"ParentingViewController parent could not be found. Please file a bug.","messagePattern":"ParentingViewController parent could not be found\\. Please file a bug\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs","lineNumber":510,"sourceCode":"\t\t{\n\t\t\tCompletePendingNavigation(false);\n\n\t\t\t_pendingNavigationRequest = new TaskCompletionSource<bool>();\n\n\t\t\t_ = page.ToPlatform(MauiContext);\n\t\t\tvar renderer = (IPlatformViewHandler)page.Handler;\n\t\t\t// renderer or ViewController can be null if a rapid push/pop causes the handler\n\t\t\t// to be torn down before this navigation completes (mirrors fix for ShellSectionRenderer #32426)\n\t\t\tif (renderer?.ViewController == null)\n\t\t\t{\n\t\t\t\tvar pendingTask = _pendingNavigationRequest.Task;\n\t\t\t\tCompletePendingNavigation(false);\n\t\t\t\treturn pendingTask;\n\t\t\t}\n\n\t\t\tvar parentViewController = renderer.ViewController.ParentViewController as ParentingViewController;\n\t\t\tif (parentViewController == null)\n\t\t\t\tthrow new NotSupportedException(\"ParentingViewController parent could not be found. Please file a bug.\");\n\n\t\t\tEventHandler appearing = null, disappearing = null;\n\t\t\tappearing = (s, e) =>\n\t\t\t{\n\t\t\t\tCompletePendingNavigation(true);\n\t\t\t};\n\n\t\t\tdisappearing = (s, e) =>\n\t\t\t{\n\t\t\t\tCompletePendingNavigation(false);\n\t\t\t};\n\n\t\t\tif (NavigationDelegate is not null)\n\t\t\t\tNavigationDelegate.WaitingForNavigationToFinish = true;\n\n\t\t\t_removeLifecycleEvents = new ActionDisposable(() =>\n\t\t\t{\n\t\t\t\t// This ensures that we don't cause multiple calls to CompletePendingNavigation.","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs#L492-L528","documentation":"Thrown during OnPushViewAsync on the iOS NavigationPage renderer when the pushed page's ViewController cannot find a ParentingViewController as its parent. The code first guards against renderer/ViewController being null (a rapid push/pop teardown fix referencing ShellSectionRenderer #32426), but if they exist and ParentViewController is not a ParentingViewController, this NotSupportedException fires. It indicates the view controller hierarchy is in an unexpected state during a push.","triggerScenarios":"Triggered when `renderer.ViewController.ParentViewController as ParentingViewController` returns null during a push. This happens when: (1) a rapid push/pop sequence tears down the handler mid-navigation but the renderer/ViewController survive (partial teardown); (2) the page's view controller was added to a non-NavigationPage container; (3) the page was already pushed to a different NavigationPage instance. The code attempts to handle pending navigation if renderer is null, but if renderer exists with a wrong parent type it throws.","commonSituations":"1) Fast programmatic navigation (multiple PushAsync then PopAsync in quick succession) where the handler is being disconnected while a push is still resolving. 2) Page shared or moved between multiple NavigationPage instances. 3) Custom navigation patterns that reparent view controllers. 4) Suspend/resume during navigation causing the platform hierarchy to be rebuilt. 5) Shell-to-NavigationPage interop edge cases.","solutions":["Avoid rapid interleaved push/pop calls — chain navigation with await and a navigation guard lock.","If the error references the rapid teardown path (renderer non-null but parent wrong), ensure the page is not being reused across NavigationPage instances.","Debounce or queue navigation operations so only one push/pop is in-flight at a time.","Check for event handler or lifecycle callback that triggers navigation during page teardown (e.g., OnDisappearing calling PushAsync).","If reproducible under normal usage, file a bug with the specific navigation sequence and device/OS version."],"exampleFix":"// before\nasync Task NavigateAround()\n{\n    await Navigation.PushAsync(new PageA());\n    await Navigation.PopAsync();\n    await Navigation.PushAsync(new PageB()); // may race with teardown\n}\n\n// after\nprivate readonly SemaphoreSlim _navLock = new(1, 1);\nasync Task NavigateAround()\n{\n    await _navLock.WaitAsync();\n    try\n    {\n        await Navigation.PushAsync(new PageA());\n        await Navigation.PopAsync();\n        await Navigation.PushAsync(new PageB());\n    }\n    finally { _navLock.Release(); }\n}","handlingStrategy":"validation","validationCode":"// Serialize navigation operations with a semaphore\nprivate readonly SemaphoreSlim _navLock = new(1, 1);\nasync Task SafePushAsync(Page page)\n{\n    await _navLock.WaitAsync();\n    try { await Navigation.PushAsync(page); }\n    finally { _navLock.Release(); }\n}","typeGuard":null,"tryCatchPattern":"try { await Navigation.PushAsync(page); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"ParentingViewController parent could not be found\"))\n{\n    // Handler teardown race — retry once after a short delay or abort gracefully","preventionTips":["Chain all navigation calls with await and a navigation guard lock.","Never trigger push/pop from OnDisappearing or teardown handlers.","Avoid sharing pages across NavigationPage instances."],"tags":["maui","ios","navigation","navigationpage","concurrency","renderer"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}