{"record":{"id":"3ecc9a6d2fb45d90","repo":"dotnet/maui","slug":"iitemsviewsource-is-empty-3ecc9a","errorCode":null,"errorMessage":"IItemsViewSource is empty","messagePattern":"IItemsViewSource is empty","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/CollectionView/EmptySource.cs","lineNumber":16,"sourceCode":"using System;\nusing Foundation;\n\nnamespace Microsoft.Maui.Controls.Compatibility.Platform.iOS\n{\n\tinternal class EmptySource : ILoopItemsViewSource\n\t{\n\t\tpublic int GroupCount => 0;\n\n\t\tpublic int ItemCount => 0;\n\n\t\tpublic bool Loop { get; set; }\n\n\t\tpublic int LoopCount => 0;\n\n\t\tpublic object this[NSIndexPath indexPath] => throw new IndexOutOfRangeException(\"IItemsViewSource is empty\");\n\n\t\tpublic int ItemCountInGroup(nint group) => 0;\n\n\t\tpublic object Group(NSIndexPath indexPath)\n\t\t{\n\t\t\tthrow new IndexOutOfRangeException(\"IItemsViewSource is empty\");\n\t\t}\n\n\t\tpublic NSIndexPath GetIndexForItem(object item)\n\t\t{\n\t\t\tthrow new IndexOutOfRangeException(\"IItemsViewSource is empty\");\n\t\t}\n\n\t\tpublic void Dispose()\n\t\t{\n\t\t}\n\t}\n}","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/CollectionView/EmptySource.cs#L1-L34","documentation":"EmptySource is a sentinel ILoopItemsViewSource with zero items, used as a no-op source when a CarouselView or CollectionView has no items. Its indexer throws IndexOutOfRangeException when accessed, because there are no valid items to return. This is a fail-fast guard against the collection view querying items from an empty source.","triggerScenarios":"The UICollectionView data source queries the item at a given NSIndexPath when the underlying source is EmptySource — typically during scroll or layout when the view still references the empty source after items were cleared or before data loaded.","commonSituations":"CollectionView/CarouselView bound to null or empty collection during initial render; items source replaced with empty collection while the view is mid-scroll; grouping with no groups; data not yet loaded from an async source.","solutions":["Check source.ItemCount > 0 before accessing items via the indexer","Provide a real items source with at least placeholder data during loading","Delay rendering the CollectionView until data is available","Handle the empty state in the UI with an EmptyView"],"exampleFix":"// before\nvar item = source[indexPath]; // throws if source is EmptySource\n\n// after\nif (source.ItemCount == 0)\n    return;\nvar item = source[indexPath];","handlingStrategy":"validation","validationCode":"// Before accessing items from a source, check count\nif (source is EmptySource || source.ItemCount == 0)\n    return null; // or show empty view\nvar item = source[indexPath];","typeGuard":"static bool HasItems(ILoopItemsViewSource source)\n{\n    return source != null && source.ItemCount > 0 && source is not EmptySource;\n}","tryCatchPattern":null,"preventionTips":["Check ItemCount > 0 before accessing items via the indexer","Provide a real items source with data before rendering the CollectionView","Use EmptyView to handle the no-data state in the UI","Delay CollectionView rendering until async data loads"],"tags":["collectionview","carousel","ios","empty-state","sentinel"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}