AvaloniaUI/Avalonia · error · NotSupportedException

Binding returned unsupported {nameof(BindingExpressionBase)}

Error message

Binding returned unsupported {nameof(BindingExpressionBase)}.

What it means

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.

Source

Thrown at src/Avalonia.Base/AvaloniaObject.cs:609

        /// <summary>
        /// Binds a <see cref="AvaloniaProperty"/> to an <see cref="BindingBase"/>.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="binding">The binding.</param>
        /// <param name="anchor">
        /// An optional anchor from which to locate required context. When binding to objects that
        /// are not in the logical tree, certain types of binding need an anchor into the tree in 
        /// order to locate named controls or resources. The <paramref name="anchor"/> parameter 
        /// can be used to provide this context.
        /// </param>
        /// <returns>
        /// The binding expression which represents the binding instance on this object.
        /// </returns>
        internal BindingExpressionBase Bind(AvaloniaProperty property, BindingBase binding, object? anchor)
        {
            if (binding.CreateInstance(this, property, anchor) is not UntypedBindingExpressionBase expression)
                throw new NotSupportedException($"Binding returned unsupported {nameof(BindingExpressionBase)}.");

            return GetValueStore().AddBinding(property, expression);
        }

        internal void AddInheritanceChild(AvaloniaObject child)
        {
            _inheritanceChildren ??= new List<AvaloniaObject>();
            _inheritanceChildren.Add(child);
        }

        internal void RemoveInheritanceChild(AvaloniaObject child)
        {
            _inheritanceChildren?.Remove(child);
        }

        /// <inheritdoc/>
        Delegate[]? IAvaloniaObjectDebug.GetPropertyChangedSubscribers()
        {

View on GitHub (pinned to 11c5427268)

Solutions

  1. Ensure any custom BindingBase.CreateInstance returns a subclass of UntypedBindingExpressionBase.
  2. Prefer using built-in binding types (Binding, CompiledBinding, MultiBinding) unless you reimplement the full contract.
  3. If you forked Avalonia, realign the return type with the current UntypedBindingExpressionBase hierarchy.

Example fix

// before (custom binding)
protected override InstancedBinding? CreateInstance(...) =>
    new InstancedBinding(...); // not an UntypedBindingExpressionBase

// after
protected override UntypedBindingExpressionBase? CreateInstance(...) =>
    new MyUntypedBindingExpression(...);
Defensive patterns

Strategy: type-guard

Validate before calling

var expr = binding.CreateInstance(target, property, anchor);
if (expr is not UntypedBindingExpressionBase)
    throw new NotSupportedException("Custom binding must return UntypedBindingExpressionBase");

Type guard

static bool ReturnsValidExpression(BindingBase b) =>
    /* author-time check */ b.GetType().GetMethod("CreateInstance")?.ReturnType
        .IsAssignableTo(typeof(UntypedBindingExpressionBase)) ?? false;

Prevention

When it happens

Trigger: Implementing a custom BindingBase whose CreateInstance returns an object not deriving from UntypedBindingExpressionBase; passing a binding whose CreateInstance was overridden incorrectly.

Common situations: Authoring custom binding extensions; version skew where an internal binding expression type changed between Avalonia releases.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/ef989b2240e2ac68. Report an issue: GitHub.