Xamarin.forms: [Bug] [iOS] Editing the ObservableCollection for a CollectionView which is not currently displayed throws out of range exception when coming back in to view

Created on 7 Feb 2020  ·  15Comments  ·  Source: xamarin/Xamarin.Forms

Description

Imagine this scenario:
A collection view is used to display a banner of thumbnail images. Clicking on an image opens a modal with a carousel allowing you swipe through the collection of images (passed through to the modal) in a larger view.
The carousel also shows a "delete" button for removing the images.
If you use this delete button and remove the image (via a call back) to the original collection, upon the modal closing (but before the appearing event of the page behind firing) iOS will crash with an out of range exception.

Steps to Reproduce

  1. Create a new app with a collection view with some items in on the first page, and a button to open the second page.
  2. Create a second page which has a button which fires an event called "RemoveItem".
  3. Handle the event on the first page and remove an item from the collection.
  4. Pop the modal
  5. The app will crash when returning to the first page.

Expected Behavior

The modal closes and the collection view on the page shows the collection with the deleted item removed.

Actual Behavior

The modal closes and the following exception is thrown:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'

Basic Information

  • Version with issue: All 4.4 (currently using 4.4.0.991640)
  • Last known good version: 4.3.0.991221
  • IDE: VS 2019 Community
  • Platform Target Frameworks:

    • iOS: iOS 13.3

  • Nuget Packages: Xamarin.Forms only
  • Affected Devices: iOS devices

Screenshots

Reproduction Link

Please see attached .zip file with a solution demonstrating the problem.
How to use:

  1. Run app
  2. Click "Page 2 to remove" button
  3. Click "Remove from collection" any number of times (once is enough)
  4. Click "Go back to page 1"
  5. Crash

CollectionView_removing_item_issue.zip

Workaround

4.3.0 collectionview 3 high regression high impact iOS 🍎 bug

Most helpful comment

@samhouts, any idea when this will be added to a sprint again?

All 15 comments

Sounds close to a duplicate of the issues discussed in #8948

Sounds close to a duplicate of the issues discussed in #8948

It does sound like it could be caused by similar scenarios. However, the exception thrown is different and I have this set up working in 4.3 where as ticked #8948 supposedly doesn't work on 4.3 either.

Sounds close to a duplicate of the issues discussed in #8948

It does sound like it could be caused by similar scenarios. However, the exception thrown is different and I have this set up working in 4.3 where as ticked #8948 supposedly doesn't work on 4.3 either.

Did you try the very last version of 4.3 (4.3.0.991250)?
CollectionView support for observable collections has been flaky for me from the beginning, but I believe offscreen support was broken by changes for #7678 in 4.3.0.991250. I'm still looking forward to the day I can confidently publish an app containing a CollectionView!

Sounds close to a duplicate of the issues discussed in #8948
It does sound like it could be caused by similar scenarios. However, the exception thrown is different and I have this set up working in 4.3 where as ticked #8948 supposedly doesn't work on 4.3 either.

Did you try the very last version of 4.3 (4.3.0.991250)?
CollectionView support for observable collections has been flaky for me from the beginning, but I believe offscreen support was broken by changes for #7678 in 4.3.0.991250. I'm still looking forward to the day I can confidently publish an app containing a CollectionView!

No I didn't try it. I'll give it a go tomorrow. Maybe I got lucky and just had a working version.

The thing is I had a a length discussion with xamarin support about how to make a page load faster since I had a page load time of 40 seconds for something that shouldn't have been that slow. The ultimate solution after a lot of back and forth was to implement a single CollectionView. Worked as intended after a week of rewriting in to my app, but I have since encountered numerous more problems!
I hope this one gets solved quickly as it is a show stopper for us.

@Jared-Aus I have confirmed this morning that 4.3.0.991250 also has the same problem.

@Jared-Aus I have confirmed this morning that 4.3.0.991250 also has the same problem.

Yep, definitely a regression issue from the changes made for that release.

@samhouts, any idea when this will be added to a sprint again?

Any update on this issue? Had to switch to a listview.

Does not work. If you add elements and switch between tabs at the same time, it crashes with the NSInternalInconsistencyException error. I do everything in the main thread

Ahhhhhhhhhhhhhhhhhhhhh. What a pain, we have released with this bug.
Sigh, tomorrow have to go through the whole process again.
Will try to roll back to 4.3.0.991221, thanks @lobbo232 for reporting this … on 8th Feb.

p.s. we were using 4.6.0.726

Edit: can't rollback due to dependencies. Will now need to look at re-designing the UI.

@RhomGit I believe you need to be on post 4.5 to be able to publish to iOS now i believe as they are rejecting Xamarin apps on older versions than that due to the UIWebViewRenderer being obsolete (whether or not you implement the WebView on your app or not).
https://docs.microsoft.com/en-gb/xamarin/xamarin-forms/user-interface/webview?tabs=windows#uiwebview-deprecation-and-app-store-rejection-itms-90809

@lobbo232 yep, thanks for that. I believe it may have been extended until December 2020 but either way rolling back is not an option as we have made commitments commercially using features post 4.3.0

We have made the decision to remove CollectionView from our product due to the consistent instability on iOS. Fun!

We have made the decision to remove CollectionView from our product due to the consistent instability on iOS. Fun!

I tested a pre-release build a few weeks ago that finally resolved this issue for me. I figured it would be in 4.6 by now. https://github.com/xamarin/Xamarin.Forms/issues/10300#issuecomment-619082950 Other iOS issues still prevent me from using a CollectionView in a real project though.

We have made the decision to remove CollectionView from our product due to the consistent instability on iOS. Fun!

CollectionView is a very unstable element. Welcome to disposed exceptions, nsinconsistency, outofrange... Visual bugs (for example, GridItemsLayout with itemspacing >0 gives a very many spaces on scrolling on ios). Slow on android (try creating a dialog app with >30 messages and you will understand me)
For now it's better to use ListView.

This is fixed in 4.6.0.1141 (possibly earlier).

BTW, the repro project has a bug; the button to return to the main page is calling PopModalAsync(), but no modal page has ever been pushed (PushAsync() was used). Unfortunately, calling PopModalAsync() without a modal on the stack _also_ results in an ArgumentOutOfRangeException, so when we originally checked this against the fixes in the last couple of versions, we thought it was still broken. Sorry for the confusion.

Was this page helpful?
0 / 5 - 0 ratings