Xamarin.forms: ArgumentOutOfRangeException on clearing a group on a grouped ListView on Android

Created on 21 Feb 2018  路  11Comments  路  Source: xamarin/Xamarin.Forms

Description

Crash on Android on clearing items in a group added to the ItemSource of a ListView.
I get a ArgumentOutOfRangeException with a stacktrace in the Xamarin.Forms namespace instead.

On iOS it works just fine.

Steps to Reproduce

A & B are lists of items created in the constructor, empty
X is the list of lists binded to the ListView

  1. Fill list A with Items
  2. Add list A & B to X
  3. Doing some async code, like loading items to be added
  4. Add Items to List B
  5. Clear list A collectionA.Clear()

Both lists A & B are never removed from X.

Expected Behavior

No crash. An empty group is also empty in the ListView and it can be cleared any time.

Actual Behavior

The App crashes with a System.ArgumentOutOfRangeException and the following Stacktrace:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
[MonoDroid] Parameter name: index
[MonoDroid]   at Xamarin.Forms.ListProxy.get_Item (System.Int32 index) [0x0000b] in D:\agent\_work\1\s\Xamarin.Forms.Core\ListProxy.cs:127 
[MonoDroid]   at Xamarin.Forms.ListProxy.System.Collections.IList.get_Item (System.Int32 index) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\ListProxy.cs:444 
[MonoDroid]   at Xamarin.Forms.Platform.Android.ListViewAdapter.GetItemViewType (System.Int32 position) [0x00076] in D:\agent\_work\1\s\Xamarin.Forms.Platform.Android\Renderers\ListViewAdapter.cs:170 
[MonoDroid]   at Android.Widget.BaseAdapter.n_GetItemViewType_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position) [0x00008] in <183d469964214eae9915d97180f9356f>:0 
[MonoDroid]   at (wrapper dynamic-method) System.Object.ac904286-5a39-409d-8d94-c363cfa06872(intptr,intptr,int)

Basic Information

Device:
Nexus 5X Android 8.1

Dependencies:
Xamarin.Forms 2.5.0.122203
Xamarin.Android.Support.* 26.1.0.1

Xamarin.Android
Version: 8.2.0.12 (Visual Studio Community)

  • Version with issue: 2.5.0.122203
  • Last known good version: Unkown
  • IDE: Visual Studio for Mac 7.4 / Rider 2017.3.1
  • Platform Target Frameworks:

    • iOS: 11.8.0.19 -> SDK 11.2

    • Android: 8.2.0.12 -> API 27 (Android 8.1)

    • UWP: --

  • Android Support Library Version: 26.1.0.1
  • Nuget Packages:
    Xamarin.Forms 2.5.0.122203
    Xamarin.Android.Support.* 26.1.0.1
    Caliburn.Micro 3.2.0
  • Affected Devices:
    Nexus 5X Android 8.1

Reproduction Link

tbd if really necessary.

Android bug

Most helpful comment

I am getting this exact exception when clearing a regular non-grouped list in Xamarin.Forms version 3.1.0.637273. Just tested with 3.2.0.871581 and it also crashes.

I clear the list that is bound to the ListView's ItemsSource, then I assign a new modified list to it.

The raw stacktrace in App Center is:

Xamarin Exception Stack:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
at Xamarin.Forms.ListProxy.get_Item (System.Int32 index) [0x0000b] in <212d41bd9b8847d3b9de286069712a07>:0
at Xamarin.Forms.ListProxy.System.Collections.IList.get_Item (System.Int32 index) [0x00000] in <212d41bd9b8847d3b9de286069712a07>:0
at Xamarin.Forms.Platform.Android.ListViewAdapter.GetDataTemplateForPath (System.Int32 indexPath) [0x0000d] in <51e92f519d4549a897820b47b1ed9602>:0
at Xamarin.Forms.Platform.Android.ListViewAdapter.GetPrototypicalCell (System.Int32 indexPath) [0x00012] in <51e92f519d4549a897820b47b1ed9602>:0
at Xamarin.Forms.Platform.Android.ListViewAdapter.IsEnabled (System.Int32 position) [0x00023] in <51e92f519d4549a897820b47b1ed9602>:0
at Android.Widget.BaseAdapter.n_IsEnabled_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position) [0x00008] in :0
at (wrapper dynamic-method) System.Object.3ad09697-63ea-4d17-95b3-7bf02d989cff(intptr,intptr,int)

Thread 1:
0 dalvik.system.VMStack.getThreadStackTrace(VMStack.java:-2)
1 java.lang.Thread.getStackTrace(Thread.java:580)
2 java.lang.Thread.getAllStackTraces(Thread.java:522)
3 com.microsoft.appcenter.crashes.Crashes.saveUncaughtException(Crashes.java:923)
4 com.microsoft.appcenter.crashes.WrapperSdkExceptionManager.saveWrapperException(WrapperSdkExceptionManager.java:50)
5 md51558244f76c53b6aeda52c8a337f2c37.ListViewAdapter.n_isEnabled(ListViewAdapter.java:-2)
6 md51558244f76c53b6aeda52c8a337f2c37.ListViewAdapter.isEnabled(ListViewAdapter.java:108)
7 android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:159)
8 android.widget.ListView.setupChild(ListView.java:1917)
9 android.widget.ListView.makeAndAddView(ListView.java:1869)
10 android.widget.ListView.fillDown(ListView.java:702)
11 android.widget.ListView.fillSpecific(ListView.java:1367)
12 android.widget.ListView.layoutChildren(ListView.java:1696)
13 android.widget.AbsListView.onLayout(AbsListView.java:2148)
14 android.view.View.layout(View.java:16647)
15 android.view.ViewGroup.layout(ViewGroup.java:5438)
16 android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:611)
17 android.view.View.layout(View.java:16647)
18 android.view.ViewGroup.layout(ViewGroup.java:5438)
19 md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer.n_onLayout(ListViewRenderer.java:-2)
20 md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer.onLayout(ListViewRenderer.java:65)
21 android.view.View.layout(View.java:16647)
22 android.view.ViewGroup.layout(ViewGroup.java:5438)
23 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
24 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
25 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
26 android.view.View.layout(View.java:16647)
27 android.view.ViewGroup.layout(ViewGroup.java:5438)
28 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
29 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
30 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
31 android.view.View.layout(View.java:16647)
32 android.view.ViewGroup.layout(ViewGroup.java:5438)
33 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
34 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
35 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
36 android.view.View.layout(View.java:16647)
37 android.view.ViewGroup.layout(ViewGroup.java:5438)
38 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
39 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
40 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
41 android.view.View.layout(View.java:16647)
42 android.view.ViewGroup.layout(ViewGroup.java:5438)
43 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
44 md51558244f76c53b6aeda52c8a337f2c37.PlatformRenderer.n_onLayout(PlatformRenderer.java:-2)
45 md51558244f76c53b6aeda52c8a337f2c37.PlatformRenderer.onLayout(PlatformRenderer.java:55)
46 android.view.View.layout(View.java:16647)
47 android.view.ViewGroup.layout(ViewGroup.java:5438)
48 android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
49 android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1732)
50 android.widget.LinearLayout.onLayout(LinearLayout.java:1497)
51 android.view.View.layout(View.java:16647)
52 android.view.ViewGroup.layout(ViewGroup.java:5438)
53 android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
54 android.widget.FrameLayout.onLayout(FrameLayout.java:273)
55 android.view.View.layout(View.java:16647)
56 android.view.ViewGroup.layout(ViewGroup.java:5438)
57 com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:493)
58 android.view.View.layout(View.java:16647)
59 android.view.ViewGroup.layout(ViewGroup.java:5438)
60 android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
61 android.widget.FrameLayout.onLayout(FrameLayout.java:273)
62 com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
63 android.view.View.layout(View.java:16647)
64 android.view.ViewGroup.layout(ViewGroup.java:5438)
65 android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2176)
66 android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1936)
67 android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1112)
68 android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6035)
69 android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
70 android.view.Choreographer.doCallbacks(Choreographer.java:670)
71 android.view.Choreographer.doFrame(Choreographer.java:606)
72 android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
73 android.os.Handler.handleCallback(Handler.java:739)
74 android.os.Handler.dispatchMessage(Handler.java:95)
75 android.os.Looper.loop(Looper.java:148)
76 android.app.ActivityThread.main(ActivityThread.java:5484)
77 java.lang.reflect.Method.invoke(Method.java:-2)
78 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
79 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

All 11 comments

Please provide a reproduction project, if possible. Thanks!

猫t voil脿: https://github.com/veryhumble/xamarin-bugreports

Actually the issue seems to be different than what I described initially. I found out that as soon as I use a GroupHeaderTemplate using a DataTemplateSelector I get the said Exception on Android but not on iOS. If no selector is used, it works.

I also added Caliburn.Micro to the NuGet packages i am using.

When submitting reproductions, please attempt to strip 3ed party references.

I have a bug with the same error #3407 on Xamarin.Forms 3.1.0.583944

In version Xamarin.Forms.3.1.0.637273 there is also crash like this.
@samhouts @rmarinho @veryhumble
ListView GroupHeaderTemplate do not work with DataTemplateSelector on Android

I am getting this exact exception when clearing a regular non-grouped list in Xamarin.Forms version 3.1.0.637273. Just tested with 3.2.0.871581 and it also crashes.

I clear the list that is bound to the ListView's ItemsSource, then I assign a new modified list to it.

The raw stacktrace in App Center is:

Xamarin Exception Stack:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
at Xamarin.Forms.ListProxy.get_Item (System.Int32 index) [0x0000b] in <212d41bd9b8847d3b9de286069712a07>:0
at Xamarin.Forms.ListProxy.System.Collections.IList.get_Item (System.Int32 index) [0x00000] in <212d41bd9b8847d3b9de286069712a07>:0
at Xamarin.Forms.Platform.Android.ListViewAdapter.GetDataTemplateForPath (System.Int32 indexPath) [0x0000d] in <51e92f519d4549a897820b47b1ed9602>:0
at Xamarin.Forms.Platform.Android.ListViewAdapter.GetPrototypicalCell (System.Int32 indexPath) [0x00012] in <51e92f519d4549a897820b47b1ed9602>:0
at Xamarin.Forms.Platform.Android.ListViewAdapter.IsEnabled (System.Int32 position) [0x00023] in <51e92f519d4549a897820b47b1ed9602>:0
at Android.Widget.BaseAdapter.n_IsEnabled_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position) [0x00008] in :0
at (wrapper dynamic-method) System.Object.3ad09697-63ea-4d17-95b3-7bf02d989cff(intptr,intptr,int)

Thread 1:
0 dalvik.system.VMStack.getThreadStackTrace(VMStack.java:-2)
1 java.lang.Thread.getStackTrace(Thread.java:580)
2 java.lang.Thread.getAllStackTraces(Thread.java:522)
3 com.microsoft.appcenter.crashes.Crashes.saveUncaughtException(Crashes.java:923)
4 com.microsoft.appcenter.crashes.WrapperSdkExceptionManager.saveWrapperException(WrapperSdkExceptionManager.java:50)
5 md51558244f76c53b6aeda52c8a337f2c37.ListViewAdapter.n_isEnabled(ListViewAdapter.java:-2)
6 md51558244f76c53b6aeda52c8a337f2c37.ListViewAdapter.isEnabled(ListViewAdapter.java:108)
7 android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:159)
8 android.widget.ListView.setupChild(ListView.java:1917)
9 android.widget.ListView.makeAndAddView(ListView.java:1869)
10 android.widget.ListView.fillDown(ListView.java:702)
11 android.widget.ListView.fillSpecific(ListView.java:1367)
12 android.widget.ListView.layoutChildren(ListView.java:1696)
13 android.widget.AbsListView.onLayout(AbsListView.java:2148)
14 android.view.View.layout(View.java:16647)
15 android.view.ViewGroup.layout(ViewGroup.java:5438)
16 android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:611)
17 android.view.View.layout(View.java:16647)
18 android.view.ViewGroup.layout(ViewGroup.java:5438)
19 md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer.n_onLayout(ListViewRenderer.java:-2)
20 md51558244f76c53b6aeda52c8a337f2c37.ListViewRenderer.onLayout(ListViewRenderer.java:65)
21 android.view.View.layout(View.java:16647)
22 android.view.ViewGroup.layout(ViewGroup.java:5438)
23 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
24 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
25 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
26 android.view.View.layout(View.java:16647)
27 android.view.ViewGroup.layout(ViewGroup.java:5438)
28 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
29 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
30 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
31 android.view.View.layout(View.java:16647)
32 android.view.ViewGroup.layout(ViewGroup.java:5438)
33 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
34 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
35 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
36 android.view.View.layout(View.java:16647)
37 android.view.ViewGroup.layout(ViewGroup.java:5438)
38 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
39 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_onLayout(VisualElementRenderer_1.java:-2)
40 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.onLayout(VisualElementRenderer_1.java:72)
41 android.view.View.layout(View.java:16647)
42 android.view.ViewGroup.layout(ViewGroup.java:5438)
43 com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout(FormsViewGroup.java:28)
44 md51558244f76c53b6aeda52c8a337f2c37.PlatformRenderer.n_onLayout(PlatformRenderer.java:-2)
45 md51558244f76c53b6aeda52c8a337f2c37.PlatformRenderer.onLayout(PlatformRenderer.java:55)
46 android.view.View.layout(View.java:16647)
47 android.view.ViewGroup.layout(ViewGroup.java:5438)
48 android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
49 android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1732)
50 android.widget.LinearLayout.onLayout(LinearLayout.java:1497)
51 android.view.View.layout(View.java:16647)
52 android.view.ViewGroup.layout(ViewGroup.java:5438)
53 android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
54 android.widget.FrameLayout.onLayout(FrameLayout.java:273)
55 android.view.View.layout(View.java:16647)
56 android.view.ViewGroup.layout(ViewGroup.java:5438)
57 com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:493)
58 android.view.View.layout(View.java:16647)
59 android.view.ViewGroup.layout(ViewGroup.java:5438)
60 android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
61 android.widget.FrameLayout.onLayout(FrameLayout.java:273)
62 com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
63 android.view.View.layout(View.java:16647)
64 android.view.ViewGroup.layout(ViewGroup.java:5438)
65 android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2176)
66 android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1936)
67 android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1112)
68 android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6035)
69 android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
70 android.view.Choreographer.doCallbacks(Choreographer.java:670)
71 android.view.Choreographer.doFrame(Choreographer.java:606)
72 android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
73 android.os.Handler.handleCallback(Handler.java:739)
74 android.os.Handler.dispatchMessage(Handler.java:95)
75 android.os.Looper.loop(Looper.java:148)
76 android.app.ActivityThread.main(ActivityThread.java:5484)
77 java.lang.reflect.Method.invoke(Method.java:-2)
78 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
79 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Same problem in 4.2.0.709249

Unhandled Exception from source=AndroidEnvironment
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
at Xamarin.Forms.ListProxy.get_Item (System.Int32 index) [0x0000b] in D:a1sXamarin.Forms.CoreListProxy.cs:127
at Xamarin.Forms.ListProxy.System.Collections.IList.get_Item (System.Int32 index) [0x00000] in D:a1sXamarin.Forms.CoreListProxy.cs:444
at Xamarin.Forms.Platform.Android.ListViewAdapter.GetItemViewType (System.Int32 position) [0x000cf] in D:a1sXamarin.Forms.Platform.AndroidRenderersListViewAdapter.cs:177
at Android.Widget.BaseAdapter.n_GetItemViewType_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position) [0x00009] in <266395aeef1642bab2007ca31686faf9>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.110(intptr,intptr,int)

Same problem in 4.3.0.947036

on a P20 Android device

ListProxy.get_Item (System.Int32 index)
IList.get_Item (System.Int32 index)
ListViewAdapter.GetItemViewType (System.Int32 position)
BaseAdapter.n_GetItemViewType_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.123(intptr,intptr,int)

Can this be reopened? I am getting this exception as well, with a different callstack. I am on version 4.3.0.991211

ListProxy.get_Item (System.Int32 index)
IList.get_Item (System.Int32 index)
ListViewAdapter.GetDataTemplateForPath (System.Int32 indexPath)
ListViewAdapter.GetPrototypicalCell (System.Int32 indexPath)
ListViewAdapter.IsEnabled (System.Int32 position)
BaseAdapter.n_IsEnabled_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.134(intptr,intptr,int)

We don't actively monitor closed issues. Can you please open a new one and attach a small sample project? Thanks!

Was this page helpful?
0 / 5 - 0 ratings