dotnet/maui · error · ArgumentOutOfRangeException
group
Error message
group
What it means
ListSource.ItemCountInGroup(nint group) throws ArgumentOutOfRangeException when group > 0. Since ListSource models exactly one group, any non-zero group index is meaningless. The guard catches grouping queries against a flat single-section source.
Source
Thrown at src/Compatibility/Core/src/iOS/CollectionView/ListSource.cs:71
if (this[n] == item)
{
return NSIndexPath.Create(0, n);
}
}
return NSIndexPath.Create(-1, -1);
}
public object Group(NSIndexPath indexPath)
{
return null;
}
public int ItemCountInGroup(nint group)
{
if (group > 0)
{
throw new ArgumentOutOfRangeException(nameof(group));
}
return Count;
}
}
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Only query per-group counts when ItemsView is in grouped mode with a GroupedItemsSource.
- Guard with `if (group == 0)` before calling ItemCountInGroup on flat sources.
- Make sure ItemsLayout and ItemsSource grouping mode are consistent.
Example fix
// before int n = source.ItemCountInGroup(group); // after int n = group == 0 ? source.ItemCountInGroup(group) : 0;
Defensive patterns
Strategy: validation
Validate before calling
// Before querying per-group count on flat source: if (group != 0) return 0;
Type guard
static bool IsValidSingleGroup(nint g) => g == 0;
Prevention
- Use grouped mode only when ItemsSource supports groups.
- Guard group == 0 for flat sources.
- Keep layout and source grouping consistent.
When it happens
Trigger: Calling ItemCountInGroup on ListSource with group > 0; UICollectionViewDelegate queries that compute per-group counts while the source is non-grouped.
Common situations: A grouped-style supplementary view or header query fired against a flat ItemsSource; switching from grouped to non-grouped layout without updating the source; index-path arithmetic that produces group >= 1.
Related errors
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/de1576f7090399ce.
Report an issue: GitHub.