Skip to content

ArgumentOutOfRangeException when calling ToList() on ItemsView.SelectedItems #10342

@tipa

Description

@tipa

Describe the bug

I crash reports I see that accessing the ItemsView.SelectedItems Property crashes for some customers.

This is the stack trace:

System.ArgumentOutOfRangeException: This collection cannot work with indices larger than Int32.MaxValue - 1 (0x7FFFFFFF - 1). (Parameter 'index')
   at ABI.System.Collections.IList.ToAbiHelper.EnsureIndexInt32(UInt32, Int32) + 0x4c
   at ABI.System.Collections.IList.ToAbiHelper.GetAt(UInt32) + 0x28
   at ABI.System.Collections.IList.Do_Abi_GetAt_0(IntPtr, UInt32, IntPtr*) + 0x62
--- End of stack trace from previous location ---
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32) + 0x39
   at WinRT.GenericTypeInstantiations.Windows_Foundation_Collections_IIterator_1_object.get_Current(IObjectReference) + 0x73
   at ABI.System.Collections.Generic.FromAbiEnumerator`1.MoveNext() + 0xaa
   at System.Collections.Generic.List`1..ctor(IEnumerable`1) + 0x78
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1) + 0x3d
   at MyApp.MyPage.get_SelectedPics() + 0x33
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object) + 0x1a
   at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0() + 0x19

Steps to reproduce the bug

itemsView.SelectedItems.ToList();

Expected behavior

No crash

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

Windows version

Windows 11 (24H2): Build 26100

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crashwhenever user reports a crash or app freezearea-AOTarea-ItemsViewbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions