Skip to content

[Bug] [Android] System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index #34247

@yevgeny-sotnikov

Description

@yevgeny-sotnikov

Description

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1[[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Item(Int32 index)
   at System.Collections.Generic.List`1[[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].System.Collections.IList.get_Item(Int32 index)
   at Microsoft.Maui.Controls.Handlers.Items.ObservableItemsSource.ElementAt(Int32 index) in /_/src/Controls/src/Core/Handlers/Items/Android/ItemsSources/ObservableItemsSource.cs:line 232
   at Microsoft.Maui.Controls.Handlers.Items.ObservableItemsSource.GetItem(Int32 position) in /_/src/Controls/src/Core/Handlers/Items/Android/ItemsSources/ObservableItemsSource.cs:line 71
   at Microsoft.Maui.Controls.Handlers.Items.UngroupedItemsSource.GetItem(Int32 position) in /_/src/Controls/src/Core/Handlers/Items/Android/ItemsSources/UngroupedItemsSource.cs:line 54
   at Microsoft.Maui.Controls.Handlers.Items.SelectableItemsViewAdapter`2[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Handlers.Items.IGroupableItemsViewSource, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null]].MarkPlatformSelection(SelectableItemsView selectableItemsView) in /_/src/Controls/src/Core/Handlers/Items/Android/Adapters/SelectableItemsViewAdapter.cs:line 107
   at Microsoft.Maui.Controls.Platform.RecyclerViewExtensions.UpdateSelection(RecyclerView recyclerView, SelectableItemsView selectableItemsView) in /_/src/Controls/src/Core/Platform/Android/Extensions/RecyclerViewExtensions.cs:line 19
   at Microsoft.Maui.Controls.Handlers.Items.SelectableItemsViewHandler`1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null]].MapSelectedItem(SelectableItemsViewHandler`1 handler, SelectableItemsView itemsView) in /_/src/Controls/src/Core/Handlers/Items/SelectableItemsViewHandler.Android.cs:line 12
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Handlers.Items.SelectableItemsViewHandler`1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) in /_/src/Core/src/PropertyMapper.cs:line 239
   at Microsoft.Maui.PropertyMapper.TryUpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) in /_/src/Core/src/PropertyMapper.cs:line 63
   at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property) in /_/src/Core/src/PropertyMapper.cs:line 114
   at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property) in /_/src/Core/src/Handlers/Element/ElementHandler.cs:line 106
   at Microsoft.Maui.Controls.Element.UpdateHandlerValue(String property, Boolean valueChanged) in /_/src/Controls/src/Core/Element/Element.cs:line 730
   at Microsoft.Maui.Controls.VisualElement.UpdateHandlerValue(String property, Boolean valueChanged) in /_/src/Controls/src/Core/VisualElement/VisualElement.cs:line 2108
   at Microsoft.Maui.Controls.Element.OnBindablePropertySet(BindableProperty property, Object original, Object value, Boolean changed, Boolean willFirePropertyChanged) in /_/src/Controls/src/Core/Element/Element.cs:line 688
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) in /_/src/Controls/src/Core/BindableObject.cs:line 676
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) in /_/src/Controls/src/Core/BindableObject.cs:line 604
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value) in /_/src/Controls/src/Core/BindableObject.cs:line 509
   at Microsoft.Maui.Controls.SelectableItemsView.set_SelectedItem(Object value) in /_/src/Controls/src/Core/Items/SelectableItemsView.cs:line 70
   at Microsoft.Maui.Controls.Handlers.Items.SelectableItemsViewAdapter`2[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Handlers.Items.IGroupableItemsViewSource, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null]].UpdateMauiSelection(Int32 adapterPosition) in /_/src/Controls/src/Core/Handlers/Items/Android/Adapters/SelectableItemsViewAdapter.cs:line 181
   at Microsoft.Maui.Controls.Handlers.Items.SelectableItemsViewAdapter`2[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Handlers.Items.IGroupableItemsViewSource, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null]].SelectableClicked(Object sender, Int32 adapterPosition) in /_/src/Controls/src/Core/Handlers/Items/Android/Adapters/SelectableItemsViewAdapter.cs:line 167
   at Microsoft.Maui.Controls.Handlers.Items.SelectableViewHolder.OnViewHolderClicked(Int32 adapterPosition) in /_/src/Controls/src/Core/Handlers/Items/Android/SelectableViewHolder.cs:line 60
   at Microsoft.Maui.Controls.Handlers.Items.SelectableViewHolder.OnClick(View view) in /_/src/Controls/src/Core/Handlers/Items/Android/SelectableViewHolder.cs:line 48
   at Android.Views.View.IOnClickListenerInvoker.n_OnClick_Landroid_view_View_(IntPtr jnienv, IntPtr native__this, IntPtr native_v)

Issue almost identical to Xamarin.Forms issue from the past: xamarin/Xamarin.Forms#15424

Steps to Reproduce

1.Create CollectionView with single selection and bind to view-model:

  <CollectionView 
        ItemsSource="{Binding Items}" 
        SelectionMode="Single"
        SelectedItem="{Binding Selecteditem}"
        SelectionChangedCommand="{Binding ItemSelectionCommand}" .....>
        ....
  </CollectionView>
  1. Buld app, click on item

Link to public reproduction project repository

No response

Version with bug

10.0.40

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

Switch to nuget-package which provides stable collection view

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/androids/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions