{"record":{"id":"c5f580170d2cb8cd","repo":"dotnet/maui","slug":"stackdepth-is-not-supported-globally-on-windows-p","errorCode":null,"errorMessage":"StackDepth is not supported globally on Windows, please use a LightNavigationPage.","messagePattern":"StackDepth is not supported globally on Windows, please use a LightNavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Interfaces/IFormsNavigation.cs","lineNumber":111,"sourceCode":"\n\t\tpublic void PushModal(object page)\n\t\t{\n\t\t\tPushModal(page, true);\n\t\t}\n\n\t\tpublic void PushModal(object page, bool animated)\n\t\t{\n\t\t\tParentWindow?.PushModal(page, animated);\n\t\t}\n\n\t\tpublic void RemovePage(object page)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\n\t\t\t\t\"RemovePage is not supported globally on Windows, please use a LightNavigationPage.\");\n\t\t}\n\n\t\tpublic int StackDepth =>\n\t\t\tthrow new InvalidOperationException(\n\t\t\t\t\"StackDepth is not supported globally on Windows, please use a LightNavigationPage.\");\n\t}\n}","sourceCodeStart":93,"sourceCodeEnd":114,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Interfaces/IFormsNavigation.cs#L93-L114","documentation":"IFormsNavigation.StackDepth is an expression-bodied property whose getter throws InvalidOperationException stating StackDepth is not supported globally on Windows and instructs to use a LightNavigationPage. Reading StackDepth on the FormsWindow navigation proxy is unsupported; only a LightNavigationPage exposes a meaningful depth.","triggerScenarios":"Reading Navigation.NavigationStack.Count or StackDepth against the window-level navigation proxy; binding/logging code that accesses StackDepth unconditionally.","commonSituations":"Cross-platform code querying stack depth for back-button enable/disable; analytics/logging reading depth on all platforms.","solutions":["Wrap pages in a LightNavigationPage and read its StackDepth.","Branch by platform or by type: read depth only when Navigation is a per-page NavigationPage.","Use the NavigationPage's NavigationStack.Count rather than the global proxy.","Guard the read with a type check (is LightNavigationPage) and fall back to 0."],"exampleFix":"// before\nvar depth = Navigation.StackDepth;\n\n// after\nvar depth = Navigation is LightNavigationPage lnp ? lnp.StackDepth : 0;","handlingStrategy":"type-guard","validationCode":"int depth = Navigation is LightNavigationPage lnp ? lnp.StackDepth : 0;","typeGuard":"static bool HasStackDepth(NavigationProxy n) => n is LightNavigationPage;","tryCatchPattern":"int depth;\ntry { depth = Navigation.StackDepth; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"LightNavigationPage\"))\n{ depth = 0; }","preventionTips":["Gate StackDepth reads behind a LightNavigationPage type check.","Branch back-button enabling logic by platform.","Avoid reading the global proxy's depth in shared code."],"tags":["wpf","navigation","not-supported","light-navigation-page","property"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}