-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] Xamarin.Forms Observablecollection throws exception on ios device #7795
Comments
@WaiseFass can you attach a repro please? I tried your steps on a physical device and didn't have any issues await Task.Delay(5000);
collection.Clear();
Enumerable.Range(0, 1000).ToList().ForEach(x => collection.Add(x.ToString()));
await Task.Delay(5000);
collection.Clear();
collection.Add("1"); |
@WaiseFass Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you! |
This is not solved, I can reproduce this error. Please reopen the issue |
1 similar comment
This is not solved, I can reproduce this error. Please reopen the issue |
This is not solved. iOS 12 using collectionview |
If you can reproduce, please add a project showing this behavior |
@jfversluis This Is the Sample you want |
and this is the error message
|
I just solve it by adding |
I'm still experiencing this issue. Task.delay is not a work around for my use case, since sometimes I need to add over 100 to 1000 items. If I were to use the "workaround" task.delay(10) the users would have to wait 10 seconds just for a simple list to load. Any other suggestions? |
@m3talelite Is it still happening in the last version of XF 4.3? |
It's still happening on the current version of XF 4.3 it happens when we insert an item into an observable collection at any random position. The same happens with the RemoveAt when we clear one of our observable collections backwards. We tried in different ways, like accessing it from different threads and the main thread of course but the issue is still occurring |
I got the same error on my Xamarin.Forms project.
|
Description
In the view model I have a observablecollection which will be created in the constructor. In the method I call the RefreshCommand, which doing the following steps:
Clears the existing list (Items.Clear())
Calls a webservice to receive new Items (async)
uses foreach to add all new Itms to the list
This items will be displayed in a ListView and this works great for Android (simulator and real device) and also for iOS Simulator, but as soon as I deploy it on a real iOS device (in this case iPhone 6), the appliction crashes..
Here is a part of the exception:
"Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out). "
I already tried it to move the clear and fill action in the GUIThread and I also tried it with a thread safe collection: https://codetraveler.io/2019/09/11/using-observablecollection-in-a-multi-threaded-xamarin-forms-application/
but the application crashes again and again.. The workaround which works for me is to change the observablecollection to a normal list...
Steps to Reproduce
Expected Behavior
the list should removes the old items and add the new ones.
It works on Android (device, simualtor) and iOS Simulator
Actual Behavior
with an iOS Device (iphone 6) the app crashes with the following exception:
"Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out). "
Basic Information
The text was updated successfully, but these errors were encountered: