{"record":{"id":"de1576f7090399ce","repo":"dotnet/maui","slug":"group","errorCode":null,"errorMessage":"group","messagePattern":"group","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/CollectionView/ListSource.cs","lineNumber":71,"sourceCode":"\t\t\t\tif (this[n] == item)\n\t\t\t\t{\n\t\t\t\t\treturn NSIndexPath.Create(0, n);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn NSIndexPath.Create(-1, -1);\n\t\t}\n\n\t\tpublic object Group(NSIndexPath indexPath)\n\t\t{\n\t\t\treturn null;\n\t\t}\n\n\t\tpublic int ItemCountInGroup(nint group)\n\t\t{\n\t\t\tif (group > 0)\n\t\t\t{\n\t\t\t\tthrow new ArgumentOutOfRangeException(nameof(group));\n\t\t\t}\n\n\t\t\treturn Count;\n\t\t}\n\t}\n}","sourceCodeStart":53,"sourceCodeEnd":77,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/CollectionView/ListSource.cs#L53-L77","documentation":"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.","triggerScenarios":"Calling ItemCountInGroup on ListSource with group > 0; UICollectionViewDelegate queries that compute per-group counts while the source is non-grouped.","commonSituations":"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.","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."],"exampleFix":"// before\nint n = source.ItemCountInGroup(group);\n// after\nint n = group == 0 ? source.ItemCountInGroup(group) : 0;","handlingStrategy":"validation","validationCode":"// Before querying per-group count on flat source:\nif (group != 0) return 0;","typeGuard":"static bool IsValidSingleGroup(nint g) => g == 0;","tryCatchPattern":null,"preventionTips":["Use grouped mode only when ItemsSource supports groups.","Guard group == 0 for flat sources.","Keep layout and source grouping consistent."],"tags":["maui","xamarin-forms","ios","uicollectionview","argument-validation","grouping"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}