dotnet/maui · error · ArgumentOutOfRangeException
indexPath
Error message
indexPath
What it means
ListSource is a single-section IItemsViewSource wrapping a plain list. Its indexer rejects any NSIndexPath whose Section is greater than 0, because ListSource only ever holds one section. This protects against a caller handing it a multi-section path that the backing data cannot satisfy.
Source
Thrown at src/Compatibility/Core/src/iOS/CollectionView/ListSource.cs:38
{
foreach (object item in enumerable)
{
Add(item);
}
}
public void Dispose()
{
}
public object this[NSIndexPath indexPath]
{
get
{
if (indexPath.Section > 0)
{
throw new ArgumentOutOfRangeException(nameof(indexPath));
}
return this[(int)indexPath.Item];
}
}
public int GroupCount => 1;
public int ItemCount => Count;
public NSIndexPath GetIndexForItem(object item)
{
for (int n = 0; n < Count; n++)
{
if (this[n] == item)
{
return NSIndexPath.Create(0, n);
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Bind a GroupedItemsSource / use GroupHeaderTemplate when your data or layout is grouped.
- Verify NSIndexPath.Section == 0 before indexing into a non-grouped ItemsViewSource.
- Ensure the items layout (Linear/Grid) matches a flat source and only use Grouped layout with group data.
Example fix
// before
var item = source[indexPath];
// after
if (indexPath.Section == 0)
item = source[indexPath]; Defensive patterns
Strategy: validation
Validate before calling
// Before indexing: if (indexPath.Section != 0) return; // ListSource is single-section
Type guard
static bool IsSingleSectionPath(NSIndexPath p) => p.Section == 0;
Prevention
- Keep ItemsLayout flat when using ListSource.
- Verify Section == 0 before indexing non-grouped sources.
- Do not pass grouped index paths to flat sources.
When it happens
Trigger: Accessing ListSource[NSIndexPath] with indexPath.Section > 0; typically an upstream caller that assumes multi-section grouping while ItemsView is bound to a flat non-grouped source.
Common situations: Switching a grouped ItemsView layout to a non-grouped one without rebinding; feeding grouped-style index paths from a header/footer supplementary view into a ListSource-backed collection; a custom layout computing paths in section 1+.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/2b0a04655af1ad0e.
Report an issue: GitHub.