Bug 29288 - Xamarin.Forms Grouped List View fails on adding new groups in Android
Summary: Xamarin.Forms Grouped List View fails on adding new groups in Android
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-04-21 21:54 UTC by Loan
Modified: 2015-05-21 20:59 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Stacktrace from Output windows when exception happens (171.77 KB, text/plain)
2015-04-21 21:54 UTC, Loan

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Loan 2015-04-21 21:54:55 UTC
Created attachment 10855 [details]
Stacktrace from Output windows when exception happens

am using Xamarin.Forms for developing mobile apps for Android and windows Phone.

I have a listview of messages which is bound to an ObservableCollection of groups. The list groups the messages by day then the messages show in order of the time - pretty standard stuff.

The problem I have now encountered is that in Android - using the Add function to add new groups to the ObservableCollection causes an unhandled exception to fire.

    04-22 13:13:32.404 D/Mono (19971): DllImport attempting to load: '/system/lib/liblog.so'. 04-22 13:13:32.404 D/Mono (19971): DllImport loaded library '/system/lib/liblog.so'. 04-22 13:13:32.404 D/Mono (19971): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so'). 04-22 13:13:32.404 D/Mono (19971): Searching for '__android_log_print'. 04-22 13:13:32.414 D/Mono
    (19971): Probing '__android_log_print'. 04-22 13:13:32.414 D/Mono
    (19971): Found as '__android_log_print'. 04-22 13:13:32.434 I/MonoDroid(19971): UNHANDLED EXCEPTION: An unhandled exception occured.

    04-22 13:13:32.444 I/MonoDroid(19971): System.ArgumentOutOfRangeException: Argument is out of range. 04-22 13:13:32.444 I/MonoDroid(19971): Parameter name: index 04-22 13:13:32.444 I/MonoDroid(19971): at System.Collections.Generic.List1<object>.get_Item (int) <0x0007c>
      04-22 13:13:32.444 I/MonoDroid(19971): at
      Cadenza.Collections.OrderedDictionary2, Xamarin.Forms.Cell>>.get_Item (int) <0x00063>

This is not a problem in Windows.

I can get around this by using the AddRange function and simply adding the item I want to add to another "temporary list" first, then add that temporary list to the main Collection - This gets around it but seems a bit of a hack.

Another way would be to do this on the main thread:

Device.BeginInvokeOnMainThread(() =>
   // using of add function in this manner works.

Has anyone had a similar problem and have you found a solution to it?

Comment 1 Eric Maupin 2015-05-21 20:59:08 UTC
It appears you're trying to add elements to the collection from another thread, as you say that "Another way would be to do this on the main thread." We don't support this directly without a little help. One way is, as you say, to use BeginInvokeOnMainThread, but another way is to use BindingBase.EnableCollectionSynchronization to educate Xamarin.Forms on how to properly synchronize with your collection.