-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] ArgumentOutOfRangeException on iOS when removing last item from a collection view with an observable ItemsSource #14171
Comments
This might be related to the issue in #9632 -- but I opened a separate issue since the stack trace was different. |
I think I managed to workaround this issue by setting IsVisible of collection view to false as soon as I know there are no items to display. XF 5.0 |
Any news about this issue? Facing that one... tried to downgrade to 4.8.0.1821 but I can't because of other issues (with RadioButton being experimental). |
I just encountered this same bug, I get ArgumentOutOfRangeExceptions out of simple .Clear() operations, XF 5.0.0.2291 |
Should fix issue: xamarin#15383 Related xamarin#14171
@MAVREE Same issue here .Clear() seems less then reliable, I have swapped many of instances of .Clear() to .ReplaceRange() instead |
I've replaced uses of the clear method with a different one where, depending on the number of items, it'll clear the collection (if more than 1 item is present) or replace the collection with a new one (if there is only 1 item in the collection). note that replacing the collection with a new one will break binding so you need to have something in place to notify the UI that the items source property has been changed. |
Description
There is a regression in XF 5 on iOS where removing the last item in an observable collection which is serving as the ItemSource for a collection view will cause a crash due to an ArgumentOutOfRangeException. Specifically, the regression was introduced in 5.0.0.1874 by this change:
2dfbf5f
This changeset modified
ObservableItemsSource.CollectionChanged
and added the following line:But this is happening before the internal state of
ObservableItemsSource
is updated--namelyItemCount
. This is problematic because checking the number of items in the section will indirectly invokeItemsViewController.CheckForEmptySource
which checksItemsSource.ItemCount
--since this property hasn't been updated yet, it causes two problems:ItemCount
will still be 0)ItemCount
will still be 1 which will ultimately lead to an attempt to determine the cell size which will attempt to access the first item in an empty collection (causing the ArgumentOutOfRangeException).Here's an example of the stack trace of the crash:
This exception was specifically generated by starting with an observable collection, adding one item, and then removing that one item. You'll notice from the stack trace that despite there being no elements in the collection, XF attempts to create the first cell to measure for layout purposes (because it doesn't realize the list is now empty).
Basic Information
Environment
Show/Hide Visual Studio info
Build Logs
Screenshots
Reproduction Link
N/A
Workaround
None.
The text was updated successfully, but these errors were encountered: