Skip to content

[Android] Prevent CollectionView EmptyView crash after handler disconnect - #38653

Merged
kubaflo merged 4 commits into
dotnet:inflight/currentfrom
Shalini-Ashokan:fix/issue-38526
Sep 21, 2026
Merged

kubaflo merged 4 commits into
dotnet:inflight/currentfrom
Shalini-Ashokan:fix/issue-38526

Conversation

@Shalini-Ashokan

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details

When a CollectionView has an EmptyView, MAUI posts a layout callback to size it.
If the handler is disconnected before that callback runs, the code still tries to access PlatformView. it crashes the application.

Root Cause

Android queues the empty-view layout work to run during the next UI-loop cycle. Meanwhile, navigation can disconnect the handler and clear its PlatformView. The queued callback later reads PlatformView, causing the “PlatformView cannot be null here” exception.

Description of Change

The native RecyclerView is saved before scheduling the delayed empty-view layout update, so the callback does not access the handler after it disconnects.
The callback safely uses this saved view to find the empty-view item and request a new layout, preventing the PlatformView cannot be null here crash.

Validated the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #38526

Output ScreenShot

Before After
BeforeFix-38526.mov
AfterFix-38526.mov

@github-actions

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 -- 38653

Or

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

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 18, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@Shalini-Ashokan! 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 dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Sep 18, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@kubaflo

This comment has been minimized.

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

Copy link
Copy Markdown
Contributor

Warning

Your /review couldn't start: the pipeline branch improved-reviewer doesn't exist. Use --branch improved-reviewer (the current reviewer branch), or omit --branch to run on main. Valid platforms: android, ios, catalyst, windows (e.g. /review android --branch improved-reviewer).

@github-actions github-actions Bot removed the s/agent-review-in-progress AI review is currently running for this PR label Sep 18, 2026
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman added platform/android area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Sep 18, 2026
@Shalini-Ashokan Shalini-Ashokan changed the title [WIP] [Android] Prevent CollectionView EmptyView crash after handler disconnect [Android] Prevent CollectionView EmptyView crash after handler disconnect Sep 18, 2026
@kubaflo

This comment has been minimized.

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

Copy link
Copy Markdown
Contributor

Warning

Your /review couldn't start: the pipeline branch improved-reviewer doesn't exist. Use --branch improved-reviewer (the current reviewer branch), or omit --branch to run on main. Valid platforms: android, ios, catalyst, windows (e.g. /review android --branch improved-reviewer).

@github-actions github-actions Bot removed the s/agent-review-in-progress AI review is currently running for this PR label Sep 18, 2026
@kubaflo

This comment has been minimized.

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

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15379549 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.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added the s/agent-approved AI agent recommends approval - PR fix is correct and optimal label Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15396557 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.

@kubaflo

This comment has been minimized.

@kubaflo
kubaflo changed the base branch from main to inflight/current September 21, 2026 11:27
@github-actions

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@Shalini-Ashokan — test-failure analysis for commit f346a6f.

Scope CI failures Commit f346a6f


🧪 CI Analysis — click to expand
📊 maui-pr

Pending; wait for this run.


🧪 maui-pr-devicetests

🧪 maui-pr-uitests

Pending; wait for this run.


🧭 Follow-up — actions and refresh

Next action: Wait for maui-pr and maui-pr-uitests; inspect the device work-item diagnostics and rerun the incomplete Android work items.

Maintainers: comment /review tests to refresh this report.

Resolve the CollectionView Android device-test conflict by retaining the queued empty-view disconnect regression and both upstream grouped empty-view tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo

kubaflo commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Resolved the merge conflict with inflight/current and pushed merge commit aa67c09 to the existing fix/issue-38526 branch.

  • Preserved DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash alongside both upstream grouped CollectionView empty-view regression tests and their required import.
  • Kept the original handler disconnect fix unchanged. This is a regular merge; no rebase or force-push.
  • Build tasks and the Android Controls device-test APK build successfully with public API validation enabled. Formatting and PR-specific whitespace checks pass.
  • Local device execution did not produce test results: the first test-host launch crashed, and the emulator was unavailable when retrying with bundled managed assemblies. No runtime test pass is claimed.

GitHub now reports the PR as mergeable (no conflicts). CI for the new commit is still pending.

@kubaflo
kubaflo merged commit 76da228 into dotnet:inflight/current Sep 21, 2026
2 of 11 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR12 milestone Sep 21, 2026
@MauiBot

MauiBot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

AI Review Summary

@Shalini-Ashokan — new AI review results are available based on commit f346a6f.

Gate Inconclusive Confidence Low Platform Android


🗂️ Review Sessions — click to expand

[!WARNING]
This run reviewed commit f346a6f, but the PR advanced to aa67c09 while it was running. These results are informational; re-run /review for the current head.


🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ INCONCLUSIVE

Platform: ANDROID · Base: main · Merge base: c97874ce

🩺 Could not verify — environment/infrastructure error. The gate ran the tests but hit an environment error (an emulator/simulator/Appium/XHarness flake, a device that would not boot, or an empty/invalid result file), so it could not record a real pass/fail. The ⚠️ ENV ERROR marks below are infrastructure, not test failures — this is not a problem with your PR. Comment /review to retry on a fresh agent.

XHarness did not produce the expected fresh result 'testResults-4b1197a69ef54a7096e8413991cc1223.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.CollectionViewTests' (the target tests did not run).

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash) Category=CollectionView ⚠️ ENV ERROR ⚠️ ENV ERROR
🔴 Without fix — 📱 CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash): ⚠️ ENV ERROR · 694s

No log file found

🟢 With fix — 📱 CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash): ⚠️ ENV ERROR · 692s

No log file found

⚠️ Failure Details

  • ⚠️ CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash) without fix: XHarness did not produce the expected fresh result 'testResults-4b1197a69ef54a7096e8413991cc1223.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.CollectionViewTests' (the target tests did not run).
  • ⚠️ CollectionViewTests (DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash) with fix: XHarness did not produce the expected fresh result 'testResults-c7fce54530c64daca4faea63f4cc1f94.xml' for requested class(es) 'Microsoft.Maui.DeviceTests.CollectionViewTests' (the target tests did not run).
📁 Fix files reverted (1 files)
  • src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs

📋 Pre-Flight — Context & Validation

Issue: #38526 - [Android] CollectionView EmptyView callback throws PlatformView cannot be null after handler disconnect
PR: #38653 - [Android] Prevent CollectionView EmptyView crash after handler disconnect
Platforms Affected: Android
Files Changed: 1 implementation, 1 test

Key Findings

  • UpdateEmptyViewSize posts an Android UI-loop callback when the EmptyView holder is not yet available; the baseline callback reads the handler's typed PlatformView after it may have been disconnected, which throws.
  • The PR captures the native RecyclerView and verifies that it is still the handler's current platform view before servicing the queued callback.
  • The added Android device test forces the measure/disconnect ordering and waits for the next looper turn. The prior Gate was inconclusive because the test environment could not build/run it; this is not evidence that the fix failed.
  • No substantive PR discussion or inline review feedback was present. The dedicated expert review is intentionally deferred to STEP 5b.

Code Review Summary

Verdict: SKIPPED
Confidence: N/A
Errors: 0 | Warnings: 0 | Suggestions: 0

Key code review findings:

  • Code review sub-agent was not launched because STEP 5a is limited to the two requested try-fix invocations; the dedicated expert pass runs in STEP 5b.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #38653 Capture the native RecyclerView and ignore the queued callback if the handler no longer owns it ⚠️ INCONCLUSIVE (Gate environment/build error) 2 files Original PR

🔬 Code Review — Deep Analysis

Code Review — PR #38653

Independent Assessment

What this changes: The Android ItemsViewHandler captures the current native RecyclerView before queuing EmptyView layout work. The queued callback compares that captured view with the nullable IElementHandler.PlatformView and exits when the handler has disconnected or reconnected to a replacement view, avoiding the throwing typed PlatformView getter after teardown. The PR also adds an Android device regression test that queues the layout callback, disconnects the handler, and waits for the next looper turn.

Inferred motivation: IElementHandler.DisconnectHandler() clears the base PlatformView before invoking handler teardown. The old callback subsequently read the non-null typed getter, which throws InvalidOperationException when the queued work outlives the handler connection.

Approach assessment: The implementation is sound and narrowly scoped. Reference identity rejects callbacks after both disconnect and reconnect while preserving the existing holder-level RequestLayout() behavior when the same native view remains connected. It adds no shared state or public API.

Reconciliation with PR Narrative

Author claims: A delayed Android EmptyView layout callback can run after handler disconnect and crash while reading PlatformView; capturing the native view and validating ownership prevents that access.

Agreement/disagreement: The code and lifecycle implementation support the claim. The callback uses the nullable interface property only for the ownership check and never evaluates the throwing typed getter after disconnect.

Prior Review Reconciliation

No prior ❌ Error findings were found across top-level reviews, inline review comments, or PR issue comments. The single authorized maui-expert-reviewer pass produced inline-findings.json with [].

Blast Radius Assessment

  • Runs for all instances: UpdateEmptyViewSize still runs during Android measure/arrange, but the changed callback path requires an EmptyViewAdapter, changed dimensions, and a holder that is not yet available.
  • Startup impact: None; this is instance-local deferred layout work.
  • Static/shared state: None.
  • Adjacent CollectionView behavior: Existing-holder layout remains synchronous, header-aware adapter positioning is unchanged, and normal item adapters and other platforms do not enter the changed branch.

CI Status

  • Required-check result: Pending for current PR HEAD aa67c09429f7de2424cd17b5c9b5618b63a6fe08; the public check-run API showed the maui-pr aggregate queued and its build/test jobs in progress.
  • Classification: Undetermined, not a PR-caused failure.
  • Trusted Gate: ⚠️ INCONCLUSIVE because the environment did not produce a usable broken-baseline result. Per the execution contract, this is not classified as a fix failure and was not rerun.
  • Action taken: Confidence is capped at low; no additional CI investigation or gate rerun was performed.

Findings

No actionable errors, warnings, or suggestions.

Failure-Mode Probing

  • Disconnect before dispatch: IElementHandler.PlatformView is null, so the callback returns without touching the throwing typed getter.
  • Disconnect and reconnect before dispatch: the replacement native view differs by reference from the captured old RecyclerView, so stale work is rejected.
  • Still connected at dispatch: identity matches, the holder lookup uses the captured live view, and the prior ItemView.RequestLayout() behavior is preserved.
  • No EmptyView or a populated source: the adapter is not EmptyViewAdapter, so behavior is unchanged.
  • Header present: the existing position calculation remains 1; the change only alters lifecycle validation.

External Output Contract

Not applicable.

Verdict: NEEDS_DISCUSSION

Confidence: low
Summary: The raw fix is correct on code inspection and the expert pass found no actionable issue. Approval cannot be recommended from this evaluation alone because current required CI is pending and the trusted regression gate is inconclusive.


🛠️ Try-Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 gpt-5.3-codex / try-fix Invalidate deferred EmptyView callbacks with a handler generation token on disconnect, then use the nullable interface platform view ✅ PASSED (2/2 scoped Android device tests) 1 file Different from the PR's captured-view ownership comparison; inline expert self-review found 0 issues
2 gpt-5.6-sol / try-fix Post a native RecyclerView layout request instead of a deferred handler-dependent ViewHolder lookup ✅ PASSED (2/2 scoped Android device tests) 1 file Avoids handler state, ownership checks, and lifecycle tokens; inline expert self-review found 0 issues
PR PR #38653 Capture the native RecyclerView and ignore the queued callback if the handler no longer owns it ⚠️ INCONCLUSIVE (Gate environment/build error) 2 files Original PR

Cross-Pollination

Model Round New Ideas? Details
N/A N/A N/A Intentionally skipped by the STEP 5a execution contract

Exhausted: Yes - the bounded two-candidate budget is complete.
Selected Fix: Candidate #2 — both alternatives passed the same primary and related EmptyView regression tests, but candidate #2 is simpler and removes the deferred handler-dependent lookup without adding mutable lifecycle state.


📝 PR Finalize — Recommended Title & Description

Assessment: ✏️ Recommend updating — the current description says the callback does not access the handler after disconnect, but the submitted code actually reads nullable IElementHandler.PlatformView to verify that the captured RecyclerView is still current before using it.

Recommended title

[Android] CollectionView: Prevent EmptyView crash after handler disconnect

Recommended description

### Issue Details

When a `CollectionView` has an `EmptyView`, MAUI posts a layout callback to size it. If the handler is disconnected before that callback runs, the previous code reads the typed `PlatformView` getter after it has been cleared and crashes the application.

### Root Cause

Android queues the EmptyView layout work for the next UI-loop cycle. Navigation can disconnect the handler and clear its `PlatformView` before that work executes. The queued callback then reads the non-null typed `PlatformView` getter, causing the “PlatformView cannot be null here” exception.

### Description of Change

The native `RecyclerView` is captured before scheduling the delayed EmptyView layout update. When the callback runs, it compares the captured view with the handler's nullable `IElementHandler.PlatformView` and returns if the handler disconnected or now owns a different native view. If the captured view is still current, the callback finds the EmptyView holder and requests layout without reading the throwing typed getter.

An Android device regression test queues the EmptyView layout callback, disconnects the handler, verifies that its platform view was cleared, and waits for the next looper turn to confirm that the callback does not crash.

### Platforms Validated

- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac

### Issues Fixed

Fixes #38526

### Output Screenshot

| Before | After |
|--|--|
| <video src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"> | <video src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613"> |

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Winning Candidate: try-fix-2

try-fix-2 is the strongest candidate because it passed both scoped Android device tests and removes the deferred callback's dependency on handler state entirely. When the EmptyView holder is unavailable, it posts RecyclerView.RequestLayout on the captured native view; the next native layout pass consumes the adapter dimensions already updated by UpdateEmptyViewSize. This is simpler than retaining a handler-aware callback and avoids new lifecycle state.

Comparative Ranking

Rank Candidate Mechanism Regression evidence Assessment
1 try-fix-2 Post a native RecyclerView.RequestLayout when the EmptyView holder is not yet available ✅ PASSED — 2/2 scoped Android device tests Best balance of correctness and simplicity. It removes the stale handler access rather than guarding it, adds no mutable state, and also avoids using a potentially stale holder position inside the deferred callback.
2 try-fix-1 Increment a handler generation on disconnect and reject callbacks from older generations ✅ PASSED — 2/2 scoped Android device tests Correctly invalidates stale work, but adds mutable lifecycle bookkeeping and still performs a deferred handler/view lookup.
3 pr Capture the native view and run the holder lookup only when it is still the handler's current platform view ⚠️ INCONCLUSIVE Gate Sound on code inspection and covered by an appropriate submitted regression test, but the trusted Gate did not verify it in the available environment.
4 pr-plus-reviewer Identical to pr; the expert pass produced no actionable refinement ⚠️ INCONCLUSIVE Gate; no separate run No worse than the raw PR, but it provides no improvement and no additional validation evidence.

No candidate failed a regression test. The two passing alternatives therefore rank above the unverified raw/reviewer candidates; the Gate's environment failure is not treated as a failing fix.

Expert Review Result

  • inline-findings.json: []
  • Actionable errors, warnings, or suggestions: none
  • Raw PR lifecycle behavior: safe on disconnect, reconnect to a replacement native view, and normal connected dispatch
  • Blast radius: localized to Android CollectionView EmptyView measure/arrange work; no public API, startup path, static state, or non-Android implementation changes

Validation and Risk

The targeted command for both try-fix candidates exercised:

  • DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash
  • NullItemsSourceDisplaysHeaderFooterAndEmptyView

Both tests passed for try-fix-2. Posting a parent RecyclerView layout is broader than requesting layout on one holder, but it occurs only when dimensions changed and that holder does not yet exist; the passing related EmptyView test provides direct evidence that layout remains correct. Current PR CI is pending, so confidence in overall merge safety remains limited even though the candidate comparison is decisive.

Required Change

Replace the submitted deferred ownership-check callback with the try-fix-2 native RecyclerView.RequestLayout approach while retaining the submitted regression test. Because an alternative candidate wins, the submitted PR should not be approved as-is.


📱 UI Tests — CollectionView

Detected UI test categories: CollectionView

❌ Deep UI tests — 615 passed, 23 failed across 1 category on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
CollectionView 615/638 (23 ❌) —
🔍 AI analysis of failures — PR-related vs unrelated

🔍 AI-generated triage (GitHub Copilot CLI) — a heuristic judgement of whether each deep UI test failure is connected to this PR's changes. Verify before relying on it.

Likely unrelated: the failures appear pre-existing, flaky, or infrastructure.

  • ● Unrelated — Android CollectionView scrolling and automation failures (23 tests): the populated-list index mismatches do not exercise the changed EmptyViewAdapter sizing callback, while the timeout and stale-element variants are nondeterministic Appium patterns rather than evidence that the callback guard affects scrolling.

Strongest signal: the production change is confined to a queued empty-view relayout during sizing and disconnect, whereas these failures involve populated scrolling positions, header interaction, or element lookup.

❌ CollectionView — 23 failed tests
VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndVerticalList_Apricot
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndVerticalList_Apricot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1824
   at System
...
VerifyGroupItemScrollToByIndexWithStartPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("FirstIndexLabel").GetText(), Is.EqualTo("13"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "13"
  But was:  "45"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3368

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3368
VerifyGroupItemScrollToByItemWithCenterPositionAndVerticalList_Potato
Assert.That(App.WaitForElement("CenterIndexLabel").GetText(), Is.EqualTo("30"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "30"
  But was:  "46"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithCenterPositionAndVerticalList_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2028

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithCenterPositionAndVerticalList_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2028
VerifyGroupItemScrollToByItemWithMakeVisiblePositionAndVerticalList_Apricot
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("24"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "24"
  But was:  "51"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithMakeVisiblePositionAndVerticalList_Apricot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1961

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithMakeVisiblePositionAndVerticalList_Apricot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1961
VerifyScrollToByItemWithMakeVisiblePositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("12"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "12"
  But was:  "29"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2473

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2473
CollectionViewHeaderShouldNotScroll
OpenQA.Selenium.StaleElementReferenceException : Cached elements 'By.id: com.microsoft.maui.uitests:id/HeaderEntry' do not exist in DOM anymore; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception
at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebElement.Execute(String commandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebElement.get_Location()
   at OpenQA.Selenium.Appium.AppiumElement.get_Rect()
   at UITest.Appium.AppiumGeneralActions.GetRect(IDictionary`2 parameters) in /_/src/TestUtils/src/UITest.Appium/Actions/AppiumGeneralActions.cs:line 51
   at UITest.Appium.AppiumGeneralActions.Execute(String commandName, IDictionary`2 parameters) in /_/src/TestUtils/src/UITest.Appium/Actions/AppiumGeneralA
...
VerifyScrollToByIndexWithStartPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2228
   at System.RuntimeMethodHan
...
VerifyScrollToByItemWithEndPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("12"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "12"
  But was:  "29"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2732

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2732
VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2833
   at System.
...
VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalGrid_Potato
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("30"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "30"
  But was:  "51"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalGrid_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3620

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalGrid_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3620
VerifyGroupIndexScrollToByIndexWithStartPositionAndVerticalList_Carrot
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithStartPositionAndVerticalList_Carrot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1860
   at System.Runtim
...
VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalGrid_Potato
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalGrid_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3193
   at System.Runtim
...
VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("13"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "13"
  But was:  "51"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3584

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3584
VerifyScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2149
   at System.RuntimeMet
...
VerifyGroupItemScrollToByItemWithStartPositionAndVerticalList_Carrot
Assert.That(App.WaitForElement("FirstIndexLabel").GetText(), Is.EqualTo("27"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "27"
  But was:  "41"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithStartPositionAndVerticalList_Carrot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1994

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByItemWithStartPositionAndVerticalList_Carrot() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1994
VerifyGroupItemScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("LastIndexLabel").GetText(), Is.EqualTo("13"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "13"
  But was:  "51"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3262

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupItemScrollToByIndexWithMakeVisiblePositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3262
VerifyScrollToByIndexWithCenterPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithCenterPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2309
   at System.RuntimeMethodHa
...
VerifyScrollToByItemWithCenterPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("CenterIndexLabel").GetText(), Is.EqualTo("12"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "12"
  But was:  "27"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithCenterPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2645

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithCenterPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2645
VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 3157
   at System.RuntimeM
...
VerifyScrollToByIndexWithEndPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByIndexWithEndPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2390
   at System.RuntimeMethodHandl
...
VerifyGroupIndexScrollToByIndexWithStartPositionAndHorizontalList_Kiwi
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2941
   at System.Runtim
...
VerifyGroupIndexScrollToByIndexWithCenterPositionAndVerticalList_Potato
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2790
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2817
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 826
   at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyGroupIndexScrollToByIndexWithCenterPositionAndVerticalList_Potato() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 1894
   at System.Runti
...
VerifyScrollToByItemWithStartPositionAndHorizontalList_Kiwi
Assert.That(App.WaitForElement("FirstIndexLabel").GetText(), Is.EqualTo("12"))
  String lengths are both 2. Strings differ at index 0.
  Expected: "12"
  But was:  "24"
  -----------^
at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2558

1)    at Microsoft.Maui.TestCases.Tests.CollectionView_ScrollingFeatureTests.VerifyScrollToByItemWithStartPositionAndHorizontalList_Kiwi() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/CollectionView_ScrollingFeatureTests.cs:line 2558

📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)


🧭 Next Steps — alternative fix proposed (try-fix-2)

Automated review — alternative fix proposed

The expert-reviewer evaluation compared the PR fix against automatically generated candidates and selected try-fix-2 as the strongest fix.

Why: try-fix-2 passed both scoped Android device tests and removes deferred handler-state access without adding lifecycle bookkeeping. Its native RecyclerView layout request is simpler than the submitted ownership guard and preserves the regression test against the PR base.

Please consider applying the candidate diff below (or use it as guidance). Once you push an update, this workflow will re-trigger and re-evaluate.

Candidate diff (try-fix-2)
diff --git a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
index 8542a9dbf5d9451432553d5ef44240b8661876b2..5401a9b8bed5dbeeaf76b01b4f80560f7a39921b 100644
--- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
+++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs
@@ -105,7 +105,8 @@ namespace Microsoft.Maui.Controls.Handlers.Items
 
 		void UpdateEmptyViewSize(double width, double height)
 		{
-			var adapter = PlatformView.GetAdapter();
+			var platformView = PlatformView;
+			var adapter = platformView.GetAdapter();
 
 			if (adapter is EmptyViewAdapter emptyViewAdapter)
 			{
@@ -124,7 +125,7 @@ namespace Microsoft.Maui.Controls.Handlers.Items
 					var emptyViewPosition = hasHeader ? 1 : 0;
 
 					// Check if ViewHolder exists and is ready for immediate layout request
-					var viewHolder = PlatformView.FindViewHolderForAdapterPosition(emptyViewPosition);
+					var viewHolder = platformView.FindViewHolderForAdapterPosition(emptyViewPosition);
 					if (viewHolder is not null)
 					{
 						// ViewHolder exists, request layout immediately to avoid frame delay
@@ -132,12 +133,8 @@ namespace Microsoft.Maui.Controls.Handlers.Items
 					}
 					else
 					{
-						// ViewHolder not created yet, defer layout request to next UI loop iteration
-						PlatformView.Post(() =>
-						{
-							var vh = PlatformView.FindViewHolderForAdapterPosition(emptyViewPosition);
-							vh?.ItemView.RequestLayout();
-						});
+						// ViewHolder not created yet, defer RecyclerView layout to the next UI loop iteration
+						platformView.Post(platformView.RequestLayout);
 					}
 				}
 			}
diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs
index 4976a590d4a0fd54888e7745e33eb768908624a1..92f45ecbeea65d81e536f3c90b6906be3a54d79e 100644
--- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs
+++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.Android.cs
@@ -105,6 +105,43 @@ namespace Microsoft.Maui.DeviceTests
 				});
 		}
 
+		[Fact]
+		public async Task DisconnectingWhileEmptyViewLayoutIsQueuedDoesNotCrash()
+		{
+			SetupBuilder();
+
+			var host = new Grid();
+
+			await CreateHandlerAndAddToWindow<LayoutHandler>(host, async _ =>
+			{
+				var collectionView = new CollectionView
+				{
+					ItemsSource = System.Array.Empty<string>(),
+					EmptyView = new Label { Text = "Empty" }
+				};
+
+				host.Add(collectionView);
+
+				var handler = Assert.IsType<CollectionViewHandler>(collectionView.Handler);
+				var platformView = handler.PlatformView;
+
+				Assert.True(platformView.IsAttachedToWindow);
+				Assert.IsType<EmptyViewAdapter>(platformView.GetAdapter());
+				Assert.Null(platformView.FindViewHolderForAdapterPosition(0));
+
+				handler.GetDesiredSize(317, 241);
+
+				host.Remove(collectionView);
+				((IElementHandler)handler).DisconnectHandler();
+
+				Assert.Null(((IElementHandler)handler).PlatformView);
+
+				var nextLooperTurn = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
+				MauiContext.Context.GetActivity().Window.DecorView.Post(() => nextLooperTurn.SetResult(true));
+				await nextLooperTurn.Task.WaitAsync(System.TimeSpan.FromSeconds(5));
+			});
+		}
+
 		//src/Compatibility/Core/tests/Android/RendererTests.cs
 		[Fact(DisplayName = "EmptySource should have a count of zero")]
 		[Trait("Category", "CollectionView")]

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Sep 21, 2026
kubaflo added a commit that referenced this pull request Sep 21, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 27, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 27, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 3, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 3, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 6, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 6, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 13, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 13, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 14, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 14, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 18, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Oct 18, 2026
…nect (#38653)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Issue Details
When a CollectionView has an EmptyView, MAUI posts a layout callback to
size it.
If the handler is disconnected before that callback runs, the code still
tries to access PlatformView. it crashes the application.

### Root Cause
Android queues the empty-view layout work to run during the next UI-loop
cycle. Meanwhile, navigation can disconnect the handler and clear its
PlatformView. The queued callback later reads PlatformView, causing the
“PlatformView cannot be null here” exception.

### Description of Change
The native RecyclerView is saved before scheduling the delayed
empty-view layout update, so the callback does not access the handler
after it disconnects.
The callback safely uses this saved view to find the empty-view item and
request a new layout, preventing the PlatformView cannot be null here
crash.

Validated the behavior in the following platforms
 
- [x] Android
- [ ] Windows
- [ ] iOS
- [ ] Mac
 
### Issues Fixed
  
Fixes #38526 

### Output  ScreenShot

|Before|After|
|--|--|
| <video
src="https://github.com/user-attachments/assets/b61c5b9c-cb57-400d-9f82-64bb08a68b4f"
>| <video
src="https://github.com/user-attachments/assets/fa9e3ab3-cd52-4eca-8966-489f5d753613">|

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates 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.

[Android] CollectionView EmptyView callback throws PlatformView cannot be null after handler disconnect

5 participants