{"record":{"id":"4fdced3caa75a6cd","repo":"AvaloniaUI/Avalonia","slug":"this-should-be-used-only-in-a-binding-expression","errorCode":null,"errorMessage":"This should be used only in a binding expression","messagePattern":"This should be used only in a binding expression","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs","lineNumber":12,"sourceCode":"﻿using System;\nusing System.Threading.Tasks;\n\nnamespace Avalonia\n{\n    public static class StreamBindingExtensions\n    {\n        internal static string StreamBindingName = \"StreamBinding\";\n\n        public static T StreamBinding<T>(this Task<T> @this)\n        {\n            throw new InvalidOperationException(\"This should be used only in a binding expression\");\n        }\n\n        public static object StreamBinding(this Task @this)\n        {\n            throw new InvalidOperationException(\"This should be used only in a binding expression\");\n        }\n\n        public static T StreamBinding<T>(this IObservable<T> @this)\n        {\n            throw new InvalidOperationException(\"This should be used only in a binding expression\");\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/StreamBindingExtensions.cs#L1-L26","documentation":"StreamBinding is a marker extension method: the compiled-binding visitor intercepts calls to StreamBinding<T>(Task<T>) inside a CompiledBinding lambda and replaces them with a stream node (StreamTask). If the method actually executes at runtime — i.e. it is called in plain code or in a reflection binding that the visitor never processes — it throws InvalidOperationException.","triggerScenarios":"Calling task.StreamBinding() directly in code-behind; using StreamBinding inside a reflection (string) Binding whose expression is not walked by BindingExpressionVisitor.","commonSituations":"Confusing the compiled-binding-only marker with a real runtime helper; using StreamBinding in a ReflectionBinding or plain C# and expecting it to return a value.","solutions":["Use StreamBinding only inside a CompiledBinding lambda, e.g. CompiledBinding.For(x => x.Loader.StreamBinding()).","For reflection bindings, bind the Task directly and handle its completion in the view-model.","Never invoke StreamBinding as a normal method."],"exampleFix":"// before (runtime call - throws)\nvar v = myTask.StreamBinding();\n// after - only inside a compiled binding\nCompiledBinding.For(x => x.Loader.StreamBinding());","handlingStrategy":"validation","validationCode":"// Ensure StreamBinding is only used inside a CompiledBinding lambda\n// (the visitor intercepts it). In plain code, drop the call:\n// bad:  var v = task.StreamBinding();\n// good: only CompiledBinding.For(x => x.Loader.StreamBinding());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat StreamBinding as a compile-time marker, not a runtime method.","Use it only inside CompiledBinding lambdas.","For reflection bindings, bind the Task and handle completion in the view-model."],"tags":["compiled-binding","stream-binding","async","binding"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}