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

  1. Only query per-group counts when ItemsView is in grouped mode with a GroupedItemsSource.
  2. Guard with `if (group == 0)` before calling ItemCountInGroup on flat sources.
  3. 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

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.