Skip to content

[Android] Don't throw an IllegalArgumentException for every page popped from a NavigationPage - #39183

Merged
kubaflo merged 2 commits into
dotnet:inflight/currentfrom
MykhailoDav:fix-31368-android-navigation-pop-exceptions
Oct 7, 2026
Merged

kubaflo merged 2 commits into
dotnet:inflight/currentfrom
MykhailoDav:fix-31368-android-navigation-pop-exceptions

Conversation

@MykhailoDav

@MykhailoDav MykhailoDav commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

On Android, every page popped from a NavigationPage throws a Java IllegalArgumentException:

Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)

MAUI catches the exception, so navigation still works. AppDomain.FirstChanceException handlers, crash reporters and the debugger output still see it. The same exception was also reported in #26375 and #30238, which were closed without a repro.

Root cause

For a pop, StackNavigationManager.ApplyNavigationRequest:

  1. calls NavController.PopBackStack(popToId, false);
  2. calls IterateBackStack to find the destinations that are no longer on the back stack, and removes them from the NavGraph.

IterateBackStack calls NavController.GetBackStackEntry for every destination in the graph. For each destination that was just popped, that call throws IllegalArgumentException, which IterateBackStack catches.

Fix

When PopBackStack succeeds, the popped destinations are removed from the graph right away. They are the entries after popToId in fragmentNavDestinations, the list the method already uses to find popToId. IterateBackStack then only finds destinations that are on the back stack. The method already removed these same destinations a few lines later, so the resulting graph and back stack don't change.

Not changed: Initialize runs when a NavigationPage handler is created with more than one page. It still calls IterateBackStack while only the first page's destination is on the back stack.

The bug also reproduces on net11.0. There, the default Android Shell handler also navigates through StackNavigationManager (ShellStackNavigationManager), so Shell back navigation throws the same exceptions too.

Tests

NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions (Core.DeviceTests, Android) pops two of three pages. During the pop, it records every IllegalArgumentException that reaches AppDomain.FirstChanceException.

Without fix With fix
PoppingPagesDoesntThrowJavaExceptions Fails: No destination with ID 3 is on the NavController's back stack, and the same for ID 4 Passes

These results are from inflight/current (262d959) on an API 37 emulator. With the fix:

Suite Category Passed
Core.DeviceTests NavigationPage 2/2
Controls.DeviceTests NavigationPage 21/21, 1 skipped
Controls.DeviceTests Modal 42/44
Controls.DeviceTests FlyoutPage 17/17
Controls.DeviceTests TabbedPage 44/48

These tests also time out on this emulator without the fix:

  • PushModalModalWithoutAwaiting (it only pushes ContentPage modals, so it doesn't run this code)
  • MovingBetweenMultiplePagesWithNestedNavigationPages, all 4 cases

On net11.0 (0b038e7), the test also fails without the fix and passes with it. Controls.DeviceTests Shell passed 151/151 there.

Issues Fixed

Fixes #31368
Fixes #35276

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39183

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39183"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Oct 6, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

/azp run

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15583282 is running for android.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@MauiBot

This comment has been minimized.

@MauiBot MauiBot added s/agent-review-incomplete AI review did not complete all expected phases s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 6, 2026
@MykhailoDav
MykhailoDav changed the base branch from main to net11.0 October 6, 2026 19:22
@MykhailoDav
MykhailoDav force-pushed the fix-31368-android-navigation-pop-exceptions branch from 8dbc1dc to 6f16080 Compare October 6, 2026 19:22
@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

/azp run

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15587418 is running for android.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@kubaflo

This comment has been minimized.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@MykhailoDav — test-failure analysis for commit 6f16080.

Scope CI failures Commit 6f16080


🧪 CI Analysis — click to expand
📊 maui-pr
  • 🟢 Likely unrelated — two Debug build failures: Windows and macOS. All five target runs show the same MSB4184 empty-version expression; this PR changes neither build properties nor targets (target diagnostic).

🧪 maui-pr-devicetests

No failures found.


🧪 maui-pr-uitests

🧭 Follow-up — actions and refresh

Next action: Restore complete UI results and variant metadata; inspect the Android crash and Windows screenshot.

Maintainers: comment /review tests to refresh this report.

@kubaflo
kubaflo changed the base branch from net11.0 to inflight/current October 7, 2026 10:01
@MykhailoDav
MykhailoDav force-pushed the fix-31368-android-navigation-pop-exceptions branch from 6f16080 to 7f50eab Compare October 7, 2026 14:07
MykhailoDav and others added 2 commits October 7, 2026 17:10
Without the fix, every popped page throws (and catches) an
IllegalArgumentException from NavController.GetBackStackEntry (dotnet#31368).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed from a NavigationPage

After a pop, ApplyNavigationRequest calls IterateBackStack to find the
destinations that left the back stack. IterateBackStack looks up every
destination of the NavGraph with NavController.GetBackStackEntry, which
throws for each destination that was just popped. The exception was
caught, but FirstChanceException handlers and crash reporters still saw
it.

Remove the popped destinations from the graph as soon as PopBackStack
succeeds. These are the same destinations the method removed afterwards.

Fixes dotnet#31368
Fixes dotnet#35276

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15598204 is running for android.

The s/agent-review-in-progress label stays on this PR while the run is active. The final recommendation and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

@MykhailoDav
MykhailoDav force-pushed the fix-31368-android-navigation-pop-exceptions branch from 7f50eab to b39a024 Compare October 7, 2026 14:32
@MauiBot

MauiBot commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

AI Review Summary

@MykhailoDav — new AI review results are available based on commit b39a024.

Gate Passed Confidence Unknown Platform Android


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ✅ PASSED

Platform: ANDROID · Base: inflight/current · Merge base: 262d9594

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 NavigationViewHandlerTests (PoppingPagesDoesntThrowJavaExceptions) Category=NavigationPage ✅ FAIL — 534s ✅ PASS — 399s
🔴 Without fix — 📱 NavigationViewHandlerTests (PoppingPagesDoesntThrowJavaExceptions): FAIL ✅ · 534s

(no coded error found; showing last 1200 chars)

"totalMemoryBytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.core.devicetests'..
info: Successfully uninstalled com.microsoft.maui.core.devicetests
XHarness exit code: 1 (TESTS_FAILED)
  Passed: 0
  Failed: 1
  Skipped: 0
  Total: 1
  Tests completed with exit code: 1
🟢 With fix — 📱 NavigationViewHandlerTests (PoppingPagesDoesntThrowJavaExceptions): PASS ✅ · 399s

(no coded error found; showing last 1200 chars)

856000,
            "totalMemoryBytes": 8322998272
          },
          "target": {
            "kind": "emulator",
            "name": "sdk_gphone_x86_64",
            "identifier": "emulator-5554",
            "operatingSystem": "Android",
            "operatingSystemVersion": "11",
            "apiLevel": 30,
            "architecture": "x86_64",
            "supportedArchitectures": [
              "x86_64",
              "x86",
              "arm64-v8a",
              "armeabi-v7a",
              "armeabi"
            ],
            "manufacturer": "Google",
            "model": "sdk_gphone_x86_64",
            "productName": "sdk_gphone_x86_64",
            "buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
            "cpuModel": "0",
            "cpuMaxFrequencyHertz": 2000,
            "totalMemoryBytes": 2077544448
          }
        }
      }
      <<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.core.devicetests'..
info: Successfully uninstalled com.microsoft.maui.core.devicetests
XHarness exit code: 0
  Passed: 1
  Failed: 0
  Skipped: 0
  Total: 1
  Tests completed successfully
📁 Fix files reverted (1 files)
  • src/Core/src/Platform/Android/Navigation/StackNavigationManager.cs

📋 Pre-Flight — Context & Validation

⚠️ Pre-Flight did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🔬 Code Review — Deep Analysis

⚠️ Code Review did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🛠️ Try-Fix — Analysis & Comparison

⚠️ Try-Fix did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


🏁 Report — Final Recommendation

⚠️ Report / Final Recommendation did not produce output on this run.

The Copilot expert-review task ended before this phase was persisted, usually because the review-stage time budget expired or the CI agent encountered a transient authentication/runtime problem. Earlier completed sections remain valid, but this review is incomplete without this phase.

Next step: re-comment /review to retry on a fresh agent. If this repeats across runs, a maintainer should inspect the reviewer token and Task 3 logs.


📱 UI Tests — ViewBaseTests

Detected UI test categories: ViewBaseTests

✅ Deep UI tests — 118 passed, 0 failed, 1 skipped across 1 category on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
ViewBaseTests 118/119 (1 skipped) ✓ —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Oct 7, 2026
@kubaflo
kubaflo merged commit 91f8812 into dotnet:inflight/current Oct 7, 2026
2 of 4 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Oct 7, 2026
kubaflo pushed a commit that referenced this pull request Oct 13, 2026
…ed from a NavigationPage (#39183)

### Description of Change

On Android, every page popped from a `NavigationPage` throws a Java
`IllegalArgumentException`:

```
Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)
```

MAUI catches the exception, so navigation still works.
`AppDomain.FirstChanceException` handlers, crash reporters and the
debugger output still see it. The same exception was also reported in
#26375 and #30238, which were closed without a repro.

**Root cause**

For a pop, `StackNavigationManager.ApplyNavigationRequest`:
1. calls `NavController.PopBackStack(popToId, false)`;
2. calls `IterateBackStack` to find the destinations that are no longer
on the back stack, and removes them from the `NavGraph`.

`IterateBackStack` calls `NavController.GetBackStackEntry` for every
destination in the graph. For each destination that was just popped,
that call throws `IllegalArgumentException`, which `IterateBackStack`
catches.

**Fix**

When `PopBackStack` succeeds, the popped destinations are removed from
the graph right away. They are the entries after `popToId` in
`fragmentNavDestinations`, the list the method already uses to find
`popToId`. `IterateBackStack` then only finds destinations that are on
the back stack. The method already removed these same destinations a few
lines later, so the resulting graph and back stack don't change.

Not changed: `Initialize` runs when a `NavigationPage` handler is
created with more than one page. It still calls `IterateBackStack` while
only the first page's destination is on the back stack.

The bug also reproduces on `net11.0`. There, the default Android Shell
handler also navigates through `StackNavigationManager`
(`ShellStackNavigationManager`), so Shell back navigation throws the
same exceptions too.

**Tests**

`NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions`
(Core.DeviceTests, Android) pops two of three pages. During the pop, it
records every `IllegalArgumentException` that reaches
`AppDomain.FirstChanceException`.

| | Without fix | With fix |
|---|---|---|
| `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with
ID 3 is on the NavController's back stack`, and the same for ID 4 |
Passes |

These results are from `inflight/current` (262d959) on an API 37
emulator. With the fix:

| Suite | Category | Passed |
|---|---|---|
| Core.DeviceTests | `NavigationPage` | 2/2 |
| Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped |
| Controls.DeviceTests | `Modal` | 42/44 |
| Controls.DeviceTests | `FlyoutPage` | 17/17 |
| Controls.DeviceTests | `TabbedPage` | 44/48 |

These tests also time out on this emulator without the fix:
- `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals,
so it doesn't run this code)
- `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases

On `net11.0` (0b038e7), the test also fails without the fix and passes
with it. Controls.DeviceTests `Shell` passed 151/151 there.

### Issues Fixed

Fixes #31368
Fixes #35276

---------
kubaflo pushed a commit that referenced this pull request Oct 14, 2026
…ed from a NavigationPage (#39183)

### Description of Change

On Android, every page popped from a `NavigationPage` throws a Java
`IllegalArgumentException`:

```
Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)
```

MAUI catches the exception, so navigation still works.
`AppDomain.FirstChanceException` handlers, crash reporters and the
debugger output still see it. The same exception was also reported in
#26375 and #30238, which were closed without a repro.

**Root cause**

For a pop, `StackNavigationManager.ApplyNavigationRequest`:
1. calls `NavController.PopBackStack(popToId, false)`;
2. calls `IterateBackStack` to find the destinations that are no longer
on the back stack, and removes them from the `NavGraph`.

`IterateBackStack` calls `NavController.GetBackStackEntry` for every
destination in the graph. For each destination that was just popped,
that call throws `IllegalArgumentException`, which `IterateBackStack`
catches.

**Fix**

When `PopBackStack` succeeds, the popped destinations are removed from
the graph right away. They are the entries after `popToId` in
`fragmentNavDestinations`, the list the method already uses to find
`popToId`. `IterateBackStack` then only finds destinations that are on
the back stack. The method already removed these same destinations a few
lines later, so the resulting graph and back stack don't change.

Not changed: `Initialize` runs when a `NavigationPage` handler is
created with more than one page. It still calls `IterateBackStack` while
only the first page's destination is on the back stack.

The bug also reproduces on `net11.0`. There, the default Android Shell
handler also navigates through `StackNavigationManager`
(`ShellStackNavigationManager`), so Shell back navigation throws the
same exceptions too.

**Tests**

`NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions`
(Core.DeviceTests, Android) pops two of three pages. During the pop, it
records every `IllegalArgumentException` that reaches
`AppDomain.FirstChanceException`.

| | Without fix | With fix |
|---|---|---|
| `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with
ID 3 is on the NavController's back stack`, and the same for ID 4 |
Passes |

These results are from `inflight/current` (262d959) on an API 37
emulator. With the fix:

| Suite | Category | Passed |
|---|---|---|
| Core.DeviceTests | `NavigationPage` | 2/2 |
| Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped |
| Controls.DeviceTests | `Modal` | 42/44 |
| Controls.DeviceTests | `FlyoutPage` | 17/17 |
| Controls.DeviceTests | `TabbedPage` | 44/48 |

These tests also time out on this emulator without the fix:
- `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals,
so it doesn't run this code)
- `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases

On `net11.0` (0b038e7), the test also fails without the fix and passes
with it. Controls.DeviceTests `Shell` passed 151/151 there.

### Issues Fixed

Fixes #31368
Fixes #35276

---------
kubaflo pushed a commit that referenced this pull request Oct 18, 2026
…ed from a NavigationPage (#39183)

### Description of Change

On Android, every page popped from a `NavigationPage` throws a Java
`IllegalArgumentException`:

```
Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)
```

MAUI catches the exception, so navigation still works.
`AppDomain.FirstChanceException` handlers, crash reporters and the
debugger output still see it. The same exception was also reported in
#26375 and #30238, which were closed without a repro.

**Root cause**

For a pop, `StackNavigationManager.ApplyNavigationRequest`:
1. calls `NavController.PopBackStack(popToId, false)`;
2. calls `IterateBackStack` to find the destinations that are no longer
on the back stack, and removes them from the `NavGraph`.

`IterateBackStack` calls `NavController.GetBackStackEntry` for every
destination in the graph. For each destination that was just popped,
that call throws `IllegalArgumentException`, which `IterateBackStack`
catches.

**Fix**

When `PopBackStack` succeeds, the popped destinations are removed from
the graph right away. They are the entries after `popToId` in
`fragmentNavDestinations`, the list the method already uses to find
`popToId`. `IterateBackStack` then only finds destinations that are on
the back stack. The method already removed these same destinations a few
lines later, so the resulting graph and back stack don't change.

Not changed: `Initialize` runs when a `NavigationPage` handler is
created with more than one page. It still calls `IterateBackStack` while
only the first page's destination is on the back stack.

The bug also reproduces on `net11.0`. There, the default Android Shell
handler also navigates through `StackNavigationManager`
(`ShellStackNavigationManager`), so Shell back navigation throws the
same exceptions too.

**Tests**

`NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions`
(Core.DeviceTests, Android) pops two of three pages. During the pop, it
records every `IllegalArgumentException` that reaches
`AppDomain.FirstChanceException`.

| | Without fix | With fix |
|---|---|---|
| `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with
ID 3 is on the NavController's back stack`, and the same for ID 4 |
Passes |

These results are from `inflight/current` (262d959) on an API 37
emulator. With the fix:

| Suite | Category | Passed |
|---|---|---|
| Core.DeviceTests | `NavigationPage` | 2/2 |
| Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped |
| Controls.DeviceTests | `Modal` | 42/44 |
| Controls.DeviceTests | `FlyoutPage` | 17/17 |
| Controls.DeviceTests | `TabbedPage` | 44/48 |

These tests also time out on this emulator without the fix:
- `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals,
so it doesn't run this code)
- `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases

On `net11.0` (0b038e7), the test also fails without the fix and passes
with it. Controls.DeviceTests `Shell` passed 151/151 there.

### Issues Fixed

Fixes #31368
Fixes #35276

---------
kubaflo pushed a commit that referenced this pull request Oct 21, 2026
…ed from a NavigationPage (#39183)

### Description of Change

On Android, every page popped from a `NavigationPage` throws a Java
`IllegalArgumentException`:

```
Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)
```

MAUI catches the exception, so navigation still works.
`AppDomain.FirstChanceException` handlers, crash reporters and the
debugger output still see it. The same exception was also reported in
#26375 and #30238, which were closed without a repro.

**Root cause**

For a pop, `StackNavigationManager.ApplyNavigationRequest`:
1. calls `NavController.PopBackStack(popToId, false)`;
2. calls `IterateBackStack` to find the destinations that are no longer
on the back stack, and removes them from the `NavGraph`.

`IterateBackStack` calls `NavController.GetBackStackEntry` for every
destination in the graph. For each destination that was just popped,
that call throws `IllegalArgumentException`, which `IterateBackStack`
catches.

**Fix**

When `PopBackStack` succeeds, the popped destinations are removed from
the graph right away. They are the entries after `popToId` in
`fragmentNavDestinations`, the list the method already uses to find
`popToId`. `IterateBackStack` then only finds destinations that are on
the back stack. The method already removed these same destinations a few
lines later, so the resulting graph and back stack don't change.

Not changed: `Initialize` runs when a `NavigationPage` handler is
created with more than one page. It still calls `IterateBackStack` while
only the first page's destination is on the back stack.

The bug also reproduces on `net11.0`. There, the default Android Shell
handler also navigates through `StackNavigationManager`
(`ShellStackNavigationManager`), so Shell back navigation throws the
same exceptions too.

**Tests**

`NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions`
(Core.DeviceTests, Android) pops two of three pages. During the pop, it
records every `IllegalArgumentException` that reaches
`AppDomain.FirstChanceException`.

| | Without fix | With fix |
|---|---|---|
| `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with
ID 3 is on the NavController's back stack`, and the same for ID 4 |
Passes |

These results are from `inflight/current` (262d959) on an API 37
emulator. With the fix:

| Suite | Category | Passed |
|---|---|---|
| Core.DeviceTests | `NavigationPage` | 2/2 |
| Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped |
| Controls.DeviceTests | `Modal` | 42/44 |
| Controls.DeviceTests | `FlyoutPage` | 17/17 |
| Controls.DeviceTests | `TabbedPage` | 44/48 |

These tests also time out on this emulator without the fix:
- `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals,
so it doesn't run this code)
- `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases

On `net11.0` (0b038e7), the test also fails without the fix and passes
with it. Controls.DeviceTests `Shell` passed 151/151 there.

### Issues Fixed

Fixes #31368
Fixes #35276

---------
kubaflo pushed a commit that referenced this pull request Oct 25, 2026
…ed from a NavigationPage (#39183)

### Description of Change

On Android, every page popped from a `NavigationPage` throws a Java
`IllegalArgumentException`:

```
Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)
```

MAUI catches the exception, so navigation still works.
`AppDomain.FirstChanceException` handlers, crash reporters and the
debugger output still see it. The same exception was also reported in
#26375 and #30238, which were closed without a repro.

**Root cause**

For a pop, `StackNavigationManager.ApplyNavigationRequest`:
1. calls `NavController.PopBackStack(popToId, false)`;
2. calls `IterateBackStack` to find the destinations that are no longer
on the back stack, and removes them from the `NavGraph`.

`IterateBackStack` calls `NavController.GetBackStackEntry` for every
destination in the graph. For each destination that was just popped,
that call throws `IllegalArgumentException`, which `IterateBackStack`
catches.

**Fix**

When `PopBackStack` succeeds, the popped destinations are removed from
the graph right away. They are the entries after `popToId` in
`fragmentNavDestinations`, the list the method already uses to find
`popToId`. `IterateBackStack` then only finds destinations that are on
the back stack. The method already removed these same destinations a few
lines later, so the resulting graph and back stack don't change.

Not changed: `Initialize` runs when a `NavigationPage` handler is
created with more than one page. It still calls `IterateBackStack` while
only the first page's destination is on the back stack.

The bug also reproduces on `net11.0`. There, the default Android Shell
handler also navigates through `StackNavigationManager`
(`ShellStackNavigationManager`), so Shell back navigation throws the
same exceptions too.

**Tests**

`NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions`
(Core.DeviceTests, Android) pops two of three pages. During the pop, it
records every `IllegalArgumentException` that reaches
`AppDomain.FirstChanceException`.

| | Without fix | With fix |
|---|---|---|
| `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with
ID 3 is on the NavController's back stack`, and the same for ID 4 |
Passes |

These results are from `inflight/current` (262d959) on an API 37
emulator. With the fix:

| Suite | Category | Passed |
|---|---|---|
| Core.DeviceTests | `NavigationPage` | 2/2 |
| Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped |
| Controls.DeviceTests | `Modal` | 42/44 |
| Controls.DeviceTests | `FlyoutPage` | 17/17 |
| Controls.DeviceTests | `TabbedPage` | 44/48 |

These tests also time out on this emulator without the fix:
- `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals,
so it doesn't run this code)
- `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases

On `net11.0` (0b038e7), the test also fails without the fix and passes
with it. Controls.DeviceTests `Shell` passed 151/151 there.

### Issues Fixed

Fixes #31368
Fixes #35276

---------
kubaflo pushed a commit that referenced this pull request Oct 26, 2026
…ed from a NavigationPage (#39183)

### Description of Change

On Android, every page popped from a `NavigationPage` throws a Java
`IllegalArgumentException`:

```
Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)
```

MAUI catches the exception, so navigation still works.
`AppDomain.FirstChanceException` handlers, crash reporters and the
debugger output still see it. The same exception was also reported in
#26375 and #30238, which were closed without a repro.

**Root cause**

For a pop, `StackNavigationManager.ApplyNavigationRequest`:
1. calls `NavController.PopBackStack(popToId, false)`;
2. calls `IterateBackStack` to find the destinations that are no longer
on the back stack, and removes them from the `NavGraph`.

`IterateBackStack` calls `NavController.GetBackStackEntry` for every
destination in the graph. For each destination that was just popped,
that call throws `IllegalArgumentException`, which `IterateBackStack`
catches.

**Fix**

When `PopBackStack` succeeds, the popped destinations are removed from
the graph right away. They are the entries after `popToId` in
`fragmentNavDestinations`, the list the method already uses to find
`popToId`. `IterateBackStack` then only finds destinations that are on
the back stack. The method already removed these same destinations a few
lines later, so the resulting graph and back stack don't change.

Not changed: `Initialize` runs when a `NavigationPage` handler is
created with more than one page. It still calls `IterateBackStack` while
only the first page's destination is on the back stack.

The bug also reproduces on `net11.0`. There, the default Android Shell
handler also navigates through `StackNavigationManager`
(`ShellStackNavigationManager`), so Shell back navigation throws the
same exceptions too.

**Tests**

`NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions`
(Core.DeviceTests, Android) pops two of three pages. During the pop, it
records every `IllegalArgumentException` that reaches
`AppDomain.FirstChanceException`.

| | Without fix | With fix |
|---|---|---|
| `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with
ID 3 is on the NavController's back stack`, and the same for ID 4 |
Passes |

These results are from `inflight/current` (262d959) on an API 37
emulator. With the fix:

| Suite | Category | Passed |
|---|---|---|
| Core.DeviceTests | `NavigationPage` | 2/2 |
| Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped |
| Controls.DeviceTests | `Modal` | 42/44 |
| Controls.DeviceTests | `FlyoutPage` | 17/17 |
| Controls.DeviceTests | `TabbedPage` | 44/48 |

These tests also time out on this emulator without the fix:
- `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals,
so it doesn't run this code)
- `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases

On `net11.0` (0b038e7), the test also fails without the fix and passes
with it. Controls.DeviceTests `Shell` passed 151/151 there.

### Issues Fixed

Fixes #31368
Fixes #35276

---------
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
…ed from a NavigationPage (#39183)

### Description of Change

On Android, every page popped from a `NavigationPage` throws a Java
`IllegalArgumentException`:

```
Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
   at androidx.navigation.NavController.getBackStackEntry(...)
```

MAUI catches the exception, so navigation still works.
`AppDomain.FirstChanceException` handlers, crash reporters and the
debugger output still see it. The same exception was also reported in
#26375 and #30238, which were closed without a repro.

**Root cause**

For a pop, `StackNavigationManager.ApplyNavigationRequest`:
1. calls `NavController.PopBackStack(popToId, false)`;
2. calls `IterateBackStack` to find the destinations that are no longer
on the back stack, and removes them from the `NavGraph`.

`IterateBackStack` calls `NavController.GetBackStackEntry` for every
destination in the graph. For each destination that was just popped,
that call throws `IllegalArgumentException`, which `IterateBackStack`
catches.

**Fix**

When `PopBackStack` succeeds, the popped destinations are removed from
the graph right away. They are the entries after `popToId` in
`fragmentNavDestinations`, the list the method already uses to find
`popToId`. `IterateBackStack` then only finds destinations that are on
the back stack. The method already removed these same destinations a few
lines later, so the resulting graph and back stack don't change.

Not changed: `Initialize` runs when a `NavigationPage` handler is
created with more than one page. It still calls `IterateBackStack` while
only the first page's destination is on the back stack.

The bug also reproduces on `net11.0`. There, the default Android Shell
handler also navigates through `StackNavigationManager`
(`ShellStackNavigationManager`), so Shell back navigation throws the
same exceptions too.

**Tests**

`NavigationViewHandlerTests.PoppingPagesDoesntThrowJavaExceptions`
(Core.DeviceTests, Android) pops two of three pages. During the pop, it
records every `IllegalArgumentException` that reaches
`AppDomain.FirstChanceException`.

| | Without fix | With fix |
|---|---|---|
| `PoppingPagesDoesntThrowJavaExceptions` | Fails: `No destination with
ID 3 is on the NavController's back stack`, and the same for ID 4 |
Passes |

These results are from `inflight/current` (262d959) on an API 37
emulator. With the fix:

| Suite | Category | Passed |
|---|---|---|
| Core.DeviceTests | `NavigationPage` | 2/2 |
| Controls.DeviceTests | `NavigationPage` | 21/21, 1 skipped |
| Controls.DeviceTests | `Modal` | 42/44 |
| Controls.DeviceTests | `FlyoutPage` | 17/17 |
| Controls.DeviceTests | `TabbedPage` | 44/48 |

These tests also time out on this emulator without the fix:
- `PushModalModalWithoutAwaiting` (it only pushes `ContentPage` modals,
so it doesn't run this code)
- `MovingBetweenMultiplePagesWithNestedNavigationPages`, all 4 cases

On `net11.0` (0b038e7), the test also fails without the fix and passes
with it. Controls.DeviceTests `Shell` passed 151/151 there.

### Issues Fixed

Fixes #31368
Fixes #35276

---------
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-review-incomplete AI review did not complete all expected phases s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when navigating back and using a NavigationPage Android navigation error when using NavigationPage

3 participants