Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Prevent ArgumentOutOfRangeException #15568

Closed
wants to merge 1 commit into from
Closed

Prevent ArgumentOutOfRangeException #15568

wants to merge 1 commit into from

Conversation

fntc
Copy link
Contributor

@fntc fntc commented Oct 17, 2022

Accessing ObservableCollection which was changed may result in an ArgumentOutOfRangeException. The exception will crash the Application because the CollectionViewRenderer cannot handle that condition in its internal drawing.

The bug is actually caused by a race condition when ItemSource is edited (cleared) while the Renderer still paints the native control and is difficult to reproduce in a simple example.

Description of Change

Check length of list before blindly accessing its indexer. This prevents an ArgumentOutOfRangeException when the ObservableCollection is changing while the CollectionViewRenderer is recalculating.

Issues Resolved

API Changes

None

Platforms Affected

  • iOS

Behavioral/Visual Changes

None (no crash)

Before/After Screenshots

Not applicable

Testing Procedure

Hard to test as this only happens when a race condition happens between Thread changing ObservableCollection data and Renderer.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

Accessing ObservableCollection which was changed may result in an ArgumentOutOfRangeException.
The exception will crash the Application because the CollectionViewRenderer cannot handle that condition in its internal drawing.

The bug is actually caused by a race condition when ItemSource is edited (cleared) while the Renderer still paints the native control and is difficult to reproduce in a simple example.
@felipemomm
Copy link
Contributor

Is anyone going to review it?
I am facing the same exact problem as we use lots of CollectionView with several changes (add/remove/update) in parallel. I am trying to update the collections in batches as much as possible, but still...

CC: @jsuarezruiz

@jfversluis
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@thisisthekap
Copy link
Contributor

@jfversluis Any chance that this one is making it into a Xamarin.Forms service release?

@jfversluis
Copy link
Member

Now that we're so close to the sunsetting of Xamarin.Forms unfortunately we won't be able to take this in anymore, we're really sorry about that. Nevertheless, thank you so much for your time and effort that you have put into this PR.

Please have a look at the evolution of Xamarin.Forms, .NET MAUI. A lot of development has been going on there. Hopefully this issue was already fixed in that codebase. If not, feel free to port this over to there.

Again, thank you so much for being a contributor and Xamarin.Forms user!

@jfversluis jfversluis closed this Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] CollectionViewRenderer ArgumentsOutOfRangeException
4 participants