Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report for Bug 45182 on
Developer Community or GitHub if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
Created attachment 17936 [details]
IndexOutOfRange errors when attempting to update an ObservableCollection bound to a ListView on a background thread. The error does not occur if the ObservableCollection was updated on the MainUI thread rather than in a background thread.
## Steps to reproduce
1. Download Sample project
2. Build Solution -> Set Android or iOS as startup project
3. Run Application
4. Noticed how after a few refreshes, the app will eventually crash with IndexOutOfRange errors.
5. Changing the updating Task in TheService.cs to start on Main thread via Device.InvokeOnMainThread will not cause an error.
## Expected Results
Xamarin.Forms application should be able to continuously update the ObservableCollection without running into IndexOutOfRange errors in the background thread. The app should be able to continue the LongRunning task.
## Actual Results
Xamarin.Forms will run into errors once sporadically once the ObservableCollection bound to the ListView it changed. The crashes look slightly different between devices but always reference IndexOutOfRange error when attempting to access the collection.
Android error logs 6.0:
>10-07 01:37:17.213 F/art ( 2004): art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: JNI CallObjectMethodA called with pending exception java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
>10-07 01:37:17.213 F/art ( 2004): art/runtime/java_vm_ext.cc:410] at throwIndexOutOfBoundsException (ArrayList.java:255)
>10-07 01:37:17.213 F/art ( 2004): art/runtime/java_vm_ext.cc:410] at get (ArrayList.java:308)
>10-07 01:37:17.213 F/art ( 2004): art/runtime/java_vm_ext.cc:410] at getView >(HeaderViewListAdapter.java:225)
>10-07 01:37:17.213 F/art ( 2004): art/runtime/java_vm_ext.cc:410] at obtainView (AbsListView.java:2346)
>10-07 01:37:17.214 F/art ( 2004): art/runtime/java_vm_ext.cc:410] at makeAndAddView (ListView.java:1875)
>10-07 01:37:17.214 F/art ( 2004): art/runtime/java_vm_ext.cc:410] at fillDown (ListView.java:702)
>10-07 01:37:17.214 F/art ( 2004): art/runtime/java_vm_ext.cc:410] at fillSpecific (ListView.java:1366)
## Version Information
Microsoft Visual Studio Enterprise 2015
Version 14.0.25425.01 Update 3
Microsoft .NET Framework
Xamarin 220.127.116.113 (3b7df6f)
Xamarin.Android 18.104.22.168 (96c7ba6)
Xamarin.iOS 10.0.1.10 (ad1cd42)
confirmed on android on master; after a few refreshes, app crashes with IndexOutOfRangeException
My understanding is that the framework assumes bounds collections will only be modified on the UI thread. If that's true, then this is not a bug. Can anyone clarify whether modifying bound ObservableCollections on threads other than the UI thread is supposed to be supported?