{"record":{"id":"c1c47eb9076de739","repo":"AvaloniaUI/Avalonia","slug":"cannot-subscribe-to-indexerdescriptor","errorCode":null,"errorMessage":"Cannot subscribe to IndexerDescriptor.","messagePattern":"Cannot subscribe to IndexerDescriptor\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/IndexerDescriptor.cs","lineNumber":109,"sourceCode":"            return this;\n        }\n\n        /// <summary>\n        /// Modifies the binding priority.\n        /// </summary>\n        /// <param name=\"priority\">The binding priority.</param>\n        /// <returns>The object that the method was called on.</returns>\n        public IndexerDescriptor WithPriority(BindingPriority priority)\n        {\n            Priority = priority;\n            return this;\n        }\n\n        /// <inheritdoc/>\n        public IDisposable Subscribe(IObserver<object?> observer)\n        {\n            if (SourceObservable is null && Source is null)\n                throw new InvalidOperationException(\"Cannot subscribe to IndexerDescriptor.\");\n            if (Property is null)\n                throw new InvalidOperationException(\"Cannot subscribe to IndexerDescriptor.\");\n\n            return (SourceObservable ?? Source!.GetObservable(Property)).Subscribe(observer);\n        }\n    }\n}\n","sourceCodeStart":91,"sourceCodeEnd":117,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/IndexerDescriptor.cs#L91-L117","documentation":"IndexerDescriptor represents an indexer-based property accessor built via the Avalonia `this[...]`/PropertyPath syntax. Subscribe requires either a SourceObservable or a Source object to pull values from; with neither, there is nothing to subscribe to, so it throws InvalidOperationException.","triggerScenarios":"Calling `descriptor.Subscribe(observer)` on an IndexerDescriptor created via the indexer operator without ever assigning `.Source` or setting a source observable (e.g. `control[ItemsControl.Items]` used standalone without a source).","commonSituations":"Building a property path/indexer descriptor for binding but forgetting to set the source. Passing a partially-constructed IndexerDescriptor to a subscriber or test.","solutions":["Assign a Source AvaloniaObject to the descriptor before subscribing, e.g. `descriptor.Source = myControl;`.","Or set SourceObservable to provide the value stream directly.","Construct the descriptor via `control[...]` on a non-null control so Source is populated automatically."],"exampleFix":"// before:\nvar d = someControl[ItemsControl.ItemsProperty];\nd.Source = null;\nd.Subscribe(obs); // throws\n\n// after:\nd.Source = someControl;\nd.Subscribe(obs);","handlingStrategy":"validation","validationCode":"if (descriptor.Source is null && descriptor.SourceObservable is null)\n    throw new InvalidOperationException(\"Set descriptor.Source or SourceObservable.\");\ndescriptor.Subscribe(observer);","typeGuard":"static bool HasSource(IndexerDescriptor d) => d.Source is not null || d.SourceObservable is not null;","tryCatchPattern":null,"preventionTips":["Build IndexerDescriptors from a non-null control so Source is set.","Explicitly assign Source or SourceObservable before subscribing.","Validate descriptor completeness in test helpers."],"tags":["bindings","indexer","property-path","invalidoperation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}