Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggling Header/Footer in CollectionView Dynamically throws an exception #25743

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

Vignesh-SF3580
Copy link
Contributor

@Vignesh-SF3580 Vignesh-SF3580 commented Nov 8, 2024

Root Cause

The issue occurred when toggling the header template in a CollectionView. Specifically, when the header was set to null and then re-assigned, an ObjectDisposedException was thrown. This happened because the platform UIView associated with the header was disposed when toggled off, but the handler for the VisualElement was not cleared, leading to a stale reference.

Description of Change

To resolve the issue, I utilized the DisconnectHandler() method provided by MAUI, which cleanly disconnects the handler from its associated platform view. This ensures that all resources tied to the handler are properly released, preventing any stale references. After calling DisconnectHandler(), formsElement is set to null to fully clear the reference, allowing the framework to initialize a fresh handler as needed. This approach maintains a consistent view lifecycle and prevents exceptions caused by attempting to access disposed views.

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #25724

Screenshots

Before Issue Fix After Issue Fix
BeforeFix.mov
Afterfix.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Nov 8, 2024
Copy link
Contributor

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

@jsuarezruiz jsuarezruiz added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Nov 8, 2024
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Vignesh-SF3580 Vignesh-SF3580 marked this pull request as ready for review November 12, 2024 05:39
@Vignesh-SF3580 Vignesh-SF3580 requested a review from a team as a code owner November 12, 2024 05:39
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@@ -577,7 +577,7 @@ internal void UpdateView(object view, DataTemplate viewTemplate, ref UIView uiVi

uiView?.Dispose();
uiView = null;

formsElement?.Handler?.DisconnectHandler();
Copy link
Member

@rmarinho rmarinho Nov 12, 2024

Choose a reason for hiding this comment

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

Do we need this fix on ItemsViewController2 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rmarinho ,
I've tested this scenario with CollectionViewHandler2, and since the header and footer handling differs in that implementation, the issue does not occur. Dynamically setting the header, footer, and empty view to null works without any exceptions in CollectionViewHandler2, so this fix isn't needed there.

@rmarinho rmarinho requested a review from jsuarezruiz November 18, 2024 03:08
@rmarinho rmarinho merged commit 3c9c96b into dotnet:main Nov 18, 2024
110 of 112 checks passed
@sheiksyedm sheiksyedm added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 6, 2024
@samhouts samhouts added fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release! labels Dec 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2025
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 fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release! partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"ObjectDisposedException" When Toggling Header/Footer in CollectionView Dynamically
6 participants