{"record":{"id":"2895ffa0c5370f55","repo":"dotnet/wpf","slug":"index-clrbindingworker","errorCode":null,"errorMessage":"index","messagePattern":"index","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ClrBindingWorker.cs","lineNumber":634,"sourceCode":"            AsyncGetValueRequest pendingGetValueRequest = (AsyncGetValueRequest)GetValue(Feature.PendingGetValueRequest, null);\n            pendingGetValueRequest?.Cancel();\n\n            // issue the new request\n            pendingGetValueRequest =\n                new AsyncGetValueRequest(item, name, ParentBinding.AsyncState,\n                                DoGetValueCallback, CompleteGetValueCallback,\n                                this, level);\n            SetValue(Feature.PendingGetValueRequest, pendingGetValueRequest);\n            Engine.AddAsyncRequest(TargetElement, pendingGetValueRequest);\n        }\n\n        private static object OnGetValueCallback(AsyncDataRequest adr)\n        {\n            AsyncGetValueRequest request = (AsyncGetValueRequest)adr;\n            ClrBindingWorker worker = (ClrBindingWorker)request.Args[0];\n            object value = worker.PW.GetValue(request.SourceItem, (int)request.Args[1]);\n            if (value == PropertyPathWorker.IListIndexOutOfRange)\n                throw new ArgumentOutOfRangeException(\"index\");\n            return value;\n        }\n\n        private static object OnCompleteGetValueCallback(AsyncDataRequest adr)\n        {\n            AsyncGetValueRequest request = (AsyncGetValueRequest)adr;\n            ClrBindingWorker worker = (ClrBindingWorker)request.Args[0];\n\n            DataBindEngine engine = worker.Engine;\n            engine?.Marshal(CompleteGetValueLocalCallback, request);\n\n            return null;\n        }\n\n        private static object OnCompleteGetValueOperation(object arg)\n        {\n            AsyncGetValueRequest request = (AsyncGetValueRequest)arg;\n            ClrBindingWorker worker = (ClrBindingWorker)request.Args[0];","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ClrBindingWorker.cs#L616-L652","documentation":"During an asynchronous binding get, if PropertyPathWorker.GetValue returns the sentinel IListIndexOutOfRange, ClrBindingWorker throws ArgumentOutOfRangeException(\"index\"). This surfaces when an async data binding indexes into an IList with an out-of-bounds index.","triggerScenarios":"An async {Binding Path=[i]} where the source list is shorter than i+1 at evaluation time (e.g. list shrunk or index computed before population).","commonSituations":"Binding to collection indexes that change as items are added/removed asynchronously; race between background updates and binding evaluation; off-by-one on count-based index bindings.","solutions":["Guard the bound index against the collection Count (e.g. bind via a converter or computed property that clamps the index)","Refresh/re-evaluate the binding after collection changes (INotifyCollectionChanged keeps indices valid)","Use an indexer property that returns null/default for out-of-range indices instead of raw list indexing"],"exampleFix":"// before\nText=\"{Binding AsyncValue[LastIndex]}\" // LastIndex may exceed Count\n// after\npublic object SafeItem(int i) => i >= 0 && i < Items.Count ? Items[i] : null;","handlingStrategy":"validation","validationCode":"object SafeGet(IList list, int i) => (i >= 0 && i < list.Count) ? list[i] : null;","typeGuard":"bool IndexIsValid(IList list, int i) => list != null && i >= 0 && i < list.Count;","tryCatchPattern":"try { /* binding evaluation */ } catch (ArgumentOutOfRangeException) { /* index out of range on source list; refresh binding */ }","preventionTips":["Keep bound list indices within Count (clamp or null-safe indexer)","Use INotifyCollectionChanged so bindings re-evaluate after changes","Avoid async bindings against rapidly resizing indexed paths"],"tags":["wpf","databinding","argument-out-of-range","async"],"backgroundTag":"index-out-of-bounds","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}