Skip to content

[NET 11][Windows] Fix CollectionView crashes when multiple CollectionViews share the same ObservableCollection - #39760

Merged
kubaflo merged 1 commit into
dotnet:net11.0from
devanathan-vaithiyanathan:fix-39751
Oct 30, 2026
Merged

kubaflo merged 1 commit into
dotnet:net11.0from
devanathan-vaithiyanathan:fix-39751

Conversation

@devanathan-vaithiyanathan

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:

On Windows, the application crashes when multiple CollectionView controls share the same ObservableCollection and one of the views is hidden.
The issue can be reproduced by binding two CollectionView controls to the same ObservableCollection, setting IsVisible to false on one of them, and then adding a new item to the collection.

Root Cause:

Collection changes trigger automatic scrolling. A collapsed WinUI view can still report IsLoaded == true without having its internal item presenter created. The previous loaded-state check therefore allowed an invalid native scroll request.

Description of Changes:

Skip scrolling related logic when the native view is collapsed

Issues Fixed

Fixes #39751

Tested the behavior in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac
Before After
Windows
Before-39751.mp4
Windows
After-39751.mp4

@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 -- 39760

Or

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

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Oct 29, 2026
@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@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 Oct 29, 2026
@azure-pipelines

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 1 finding

Reviewed commit bf5052d.

See inline comments for details.

items.Add("Item 4");
handler.PlatformView.UpdateLayout();
await Task.Delay(100);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[moderate] Regression Prevention and Test Coverage - The visible CollectionView does not provide a discriminating negative test for the new visibility guard: its only assertions compare ItemsSource contents, which are updated independently of ApplyItemsUpdatingScrollMode. The reveal assertions likewise check loaded labels rather than scrolling, and the fixture starts with only three 40px rows in a 200px viewport. Returning unconditionally from ApplyItemsUpdatingScrollMode would still satisfy these assertions, while breaking automatic scrolling for visible views. Add an overflowing visible-view case and assert the resulting scroll position for both modes (starting away from the first item for KeepItemsInView), so the test proves that visible updates are not suppressed along with hidden ones.

@MauiBot

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@devanathan-vaithiyanathan — test-failure analysis for commit bf5052d.

Scope CI failures Commit bf5052d


🧪 CI Analysis — click to expand
📊 maui-pr

No failures found.


🧪 maui-pr-devicetests
  • 🟡 Needs human investigation — InteractivePopGesture: 24 renderer-type assertions, MacCatalyst CoreCLR / iOS Mono/CoreCLR; target history lacks comparable assertions/parameters.
  • 🟡 Needs human investigation — ResetRestoresNativeAppearance: 12 false assertions, MacCatalyst / iOS; both tint variants lack reason-complete target evidence.
  • 🟡 Needs human investigation — Android Mono InvokeDotNet: 25-second HybridWebView readiness timeout plus crash evidence; no matching target diagnostic.
  • 🟡 Needs human investigation — Two MacCatalyst crash-marked work items (macOS 15, 26); iOS Mono termination also needs completion verification. Inspect termination diagnostics, not wrapper exit codes.

🧪 maui-pr-uitests

🧭 Follow-up — actions and refresh

Next action: Restore evidence; inspect device termination and CV1 snapshot packaging. Do not duplicate existing runs.

Maintainers: comment /review tests to refresh this report.

@devanathan-vaithiyanathan devanathan-vaithiyanathan changed the title [WIP][NET 11][Windows] Fix CollectionView crashes when multiple CollectionViews share the same ObservableCollection [NET 11][Windows] Fix CollectionView crashes when multiple CollectionViews share the same ObservableCollection Oct 30, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review October 30, 2026 07:22
Copilot AI balanced review requested due to automatic review settings October 30, 2026 07:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Windows runtime validation remains necessary because deferred scroll callbacks recheck only IsLoaded after visibility may change, and the added device tests were not executed.

No open issues 🎉

What changed in this PR

Addresses #39751, a .NET 11 Windows CollectionView regression where updating a shared ObservableCollection can crash when one bound view is hidden. The fix guards automatic scrolling in the Items2 handler.

Changes:

  • Skip item-update scrolling when the native view is collapsed, even if it reports being loaded.
  • Add Windows device tests covering shared-source updates, visibility transitions, collection mutations, and both supported automatic-scroll modes.
File Description
src/​Controls/​tests/​DeviceTests/​Elements/​CollectionView/​CollectionViewTests.Windows.cs Adds regression coverage for visible and hidden CollectionViews sharing a collection.
src/​Controls/​src/​Core/​Handlers/​Items2/​ItemsViewHandler2.Windows.cs Adds a native visibility check before automatic scrolling.

Review effort: Balanced

@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 Oct 30, 2026
@MauiBot

MauiBot commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@devanathan-vaithiyanathan — existing-test verification for commit bf5052d9.

Result PASSED Platform Windows Commit bf5052d9


🧪 Gate analysis — click to expand

✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence.

📱 Device tests
Test group Without fix With fix
CollectionViewTests (CollectionView2SharedItemsSourceUpdatesWhileHidden) ✅ Failed as expected (837s) ✅ Passed (205s)
Execution log excerpts

Without fix CollectionViewTests (CollectionView2SharedItemsSourceUpdatesWhileHidden)

WINDOWS_DEVICE_TEST_NO_RESULTS: Windows device test result file 'D:\a\1\s\CustomAgentLogsTmp\PRState\39760\PRAgent\gate\verify-tests-fail\test-without-fix-CollectionViewTests__CollectionView2SharedItemsSourceUpdates.log.diagnostics\TestResults-Microsoft_Maui_Controls_DeviceTests_CollectionView.xml' is empty or not valid XML (the device-test app likely crashed or exited before writing results).

With fix CollectionViewTests (CollectionView2SharedItemsSourceUpdatesWhileHidden)

uppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net11.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(19,21): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net11.0-windows10.0.19041.0]
    0 Error(s)
Time Elapsed 00:02:25.21
  Passed: 4
  Failed: 0
  Skipped: 0
  Total: 4
  Tests completed successfully

PR head: bf5052d9.

Without-fix baseline: 7de2a9f2.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Oct 30, 2026
@kubaflo
kubaflo merged commit b346503 into dotnet:net11.0 Oct 30, 2026
157 of 181 checks passed
@github-actions github-actions Bot added this to the .NET 11.0-rc2 milestone Oct 30, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — bf5052d9 Deployed Oct 29, 2026 by devanathan-vaithiyanathan via conclusion #2581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-winui-cv2 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants