Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

Prevent ArgumentOutOfRangeException

Open fntc opened this issue 3 years ago • 4 comments

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

  • fixes #15567

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)

fntc avatar Oct 17 '22 11:10 fntc

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

felipemomm avatar Feb 10 '23 10:02 felipemomm

/azp run

jfversluis avatar Feb 15 '23 08:02 jfversluis

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Feb 15 '23 08:02 azure-pipelines[bot]

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

thisisthekap avatar Jan 18 '24 10:01 thisisthekap

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 avatar Apr 25 '24 08:04 jfversluis