{"record":{"id":"f9114917ed875edf","repo":"dotnet/maui","slug":"indexpath-f91149","errorCode":null,"errorMessage":"indexPath","messagePattern":"indexPath","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/CollectionView/ObservableItemsSource.cs","lineNumber":94,"sourceCode":"\t\t\t\t{\n\t\t\t\t\treturn NSIndexPath.Create(_section, 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 int GroupCount => 1;\n\n\t\tpublic int ItemCount => Count;\n\n\t\tpublic object this[NSIndexPath indexPath]\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tif (indexPath.Section != _section)\n\t\t\t\t{\n\t\t\t\t\tthrow new ArgumentOutOfRangeException(nameof(indexPath));\n\t\t\t\t}\n\n\t\t\t\treturn this[(int)indexPath.Item];\n\t\t\t}\n\t\t}\n\n\t\tvoid CollectionChanged(object sender, NotifyCollectionChangedEventArgs args)\n\t\t{\n\t\t\tCollectionView.BeginInvokeOnMainThread(() => CollectionChanged(args));\n\t\t}\n\n\t\tvoid CollectionChanged(NotifyCollectionChangedEventArgs args)\n\t\t{\n\t\t\t// Force UICollectionView to get the internal accounting straight \n\t\t\tif (!CollectionView.Hidden)\n\t\t\t\tCollectionView.NumberOfItemsInSection(_section);\n\n\t\t\tswitch (args.Action)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/CollectionView/ObservableItemsSource.cs#L76-L112","documentation":"ObservableItemsSource wraps an ObservableCollection for an iOS ItemsView and is pinned to a single section (_section). The indexer throws ArgumentOutOfRangeException when indexPath.Section != _section, ensuring callers stay within the assigned section. This protects against multi-section paths hitting a section-bound observable wrapper.","triggerScenarios":"Indexing ObservableItemsSource with an NSIndexPath whose Section does not equal the value passed at construction; e.g. a layout/UI update that recomputes sections while the wrapper still owns only its original section.","commonSituations":"ObservableCollection rebinding while a reload is in flight; mixing grouped layouts with a non-grouped observable source; a section index mismatch after Insert/Delete animations on the underlying collection.","solutions":["Keep ItemsLayout grouping consistent with the source — flat layout with ObservableCollection, grouped layout with grouped data.","Avoid replacing the ItemsSource during an in-flight batch update; let the existing ObservableItemsSource finish.","Confirm that any NSIndexPath passed to the indexer has Section equal to the section the wrapper was created for."],"exampleFix":"// before\nvar item = source[indexPath];\n// after\nif (indexPath.Section == source.Section)\n    item = source[indexPath];","handlingStrategy":"validation","validationCode":"// ObservableItemsSource is pinned to a single section.\nif (indexPath.Section != expectedSection) return;","typeGuard":"static bool MatchesSection(NSIndexPath p, nint section) => p.Section == section;","tryCatchPattern":null,"preventionTips":["Do not change grouping while an ObservableItemsSource is active.","Confirm indexPath.Section matches the wrapper's section.","Avoid rebinding ItemsSource during in-flight batch updates."],"tags":["maui","xamarin-forms","ios","uicollectionview","observablecollection","argument-validation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}