Xamarin.Forms
                                
                                
                                
                                    Xamarin.Forms copied to clipboard
                            
                            
                            
                        Prevent ArgumentOutOfRangeException
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)
 
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
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
@jfversluis Any chance that this one is making it into a Xamarin.Forms service release?
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!