{"record":{"id":"ef989b2240e2ac68","repo":"AvaloniaUI/Avalonia","slug":"binding-returned-unsupported-nameof-bindingexpres","errorCode":null,"errorMessage":"Binding returned unsupported {nameof(BindingExpressionBase)}.","messagePattern":"Binding returned unsupported (.+?)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/AvaloniaObject.cs","lineNumber":609,"sourceCode":"\n        /// <summary>\n        /// Binds a <see cref=\"AvaloniaProperty\"/> to an <see cref=\"BindingBase\"/>.\n        /// </summary>\n        /// <param name=\"property\">The property.</param>\n        /// <param name=\"binding\">The binding.</param>\n        /// <param name=\"anchor\">\n        /// An optional anchor from which to locate required context. When binding to objects that\n        /// are not in the logical tree, certain types of binding need an anchor into the tree in \n        /// order to locate named controls or resources. The <paramref name=\"anchor\"/> parameter \n        /// can be used to provide this context.\n        /// </param>\n        /// <returns>\n        /// The binding expression which represents the binding instance on this object.\n        /// </returns>\n        internal BindingExpressionBase Bind(AvaloniaProperty property, BindingBase binding, object? anchor)\n        {\n            if (binding.CreateInstance(this, property, anchor) is not UntypedBindingExpressionBase expression)\n                throw new NotSupportedException($\"Binding returned unsupported {nameof(BindingExpressionBase)}.\");\n\n            return GetValueStore().AddBinding(property, expression);\n        }\n\n        internal void AddInheritanceChild(AvaloniaObject child)\n        {\n            _inheritanceChildren ??= new List<AvaloniaObject>();\n            _inheritanceChildren.Add(child);\n        }\n\n        internal void RemoveInheritanceChild(AvaloniaObject child)\n        {\n            _inheritanceChildren?.Remove(child);\n        }\n\n        /// <inheritdoc/>\n        Delegate[]? IAvaloniaObjectDebug.GetPropertyChangedSubscribers()\n        {","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/AvaloniaObject.cs#L591-L627","documentation":"Thrown by AvaloniaObject.Bind when binding.CreateInstance does not return an UntypedBindingExpressionBase. The internal Bind expects every BindingBase to produce an untyped expression it can register with the value store; a binding returning a different expression type is treated as a programmer/library-author error.","triggerScenarios":"Implementing a custom BindingBase whose CreateInstance returns an object not deriving from UntypedBindingExpressionBase; passing a binding whose CreateInstance was overridden incorrectly.","commonSituations":"Authoring custom binding extensions; version skew where an internal binding expression type changed between Avalonia releases.","solutions":["Ensure any custom BindingBase.CreateInstance returns a subclass of UntypedBindingExpressionBase.","Prefer using built-in binding types (Binding, CompiledBinding, MultiBinding) unless you reimplement the full contract.","If you forked Avalonia, realign the return type with the current UntypedBindingExpressionBase hierarchy."],"exampleFix":"// before (custom binding)\nprotected override InstancedBinding? CreateInstance(...) =>\n    new InstancedBinding(...); // not an UntypedBindingExpressionBase\n\n// after\nprotected override UntypedBindingExpressionBase? CreateInstance(...) =>\n    new MyUntypedBindingExpression(...);","handlingStrategy":"type-guard","validationCode":"var expr = binding.CreateInstance(target, property, anchor);\nif (expr is not UntypedBindingExpressionBase)\n    throw new NotSupportedException(\"Custom binding must return UntypedBindingExpressionBase\");","typeGuard":"static bool ReturnsValidExpression(BindingBase b) =>\n    /* author-time check */ b.GetType().GetMethod(\"CreateInstance\")?.ReturnType\n        .IsAssignableTo(typeof(UntypedBindingExpressionBase)) ?? false;","tryCatchPattern":null,"preventionTips":["Reuse built-in BindingBase subclasses; only subclass UntypedBindingExpressionBase when authoring custom bindings.","Add unit tests asserting CreateInstance's return type."],"tags":["binding","avaloniaobject","not-supported","extension-authoring"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}