AvaloniaUI/Avalonia · error · NotSupportedException

Unsupported AvaloniaProperty type.

Error message

Unsupported AvaloniaProperty type.

What it means

Thrown by AvaloniaObjectExtensions.Bind<T>(AvaloniaProperty<T>, IObservable<BindingValue<T>>) when the property is neither StyledProperty<T> nor DirectPropertyBase<T>. The extension dispatches on runtime type; an unrecognized AvaloniaProperty<T> subclass falls to the default arm.

Source

Thrown at src/Avalonia.Base/AvaloniaObjectExtensions.cs:202

        /// <param name="priority">The priority of the binding.</param>
        /// <returns>
        /// A disposable which can be used to terminate the binding.
        /// </returns>
        public static IDisposable Bind<T>(
            this AvaloniaObject target,
            AvaloniaProperty<T> property,
            IObservable<BindingValue<T>> source,
            BindingPriority priority = BindingPriority.LocalValue)
        {
            target = target ?? throw new ArgumentNullException(nameof(target));
            property = property ?? throw new ArgumentNullException(nameof(property));
            source = source ?? throw new ArgumentNullException(nameof(source));

            return property switch
            {
                StyledProperty<T> styled => target.Bind(styled, source, priority),
                DirectPropertyBase<T> direct => target.Bind(direct, source),
                _ => throw new NotSupportedException("Unsupported AvaloniaProperty type."),
            };
        }

        /// <summary>
        /// Binds an <see cref="AvaloniaProperty"/> to an observable.
        /// </summary>
        /// <param name="target">The object.</param>
        /// <param name="property">The property.</param>
        /// <param name="source">The observable.</param>
        /// <param name="priority">The priority of the binding.</param>
        /// <returns>
        /// A disposable which can be used to terminate the binding.
        /// </returns>
        public static IDisposable Bind<T>(
            this AvaloniaObject target,
            AvaloniaProperty<T> property,
            IObservable<T> source,
            BindingPriority priority = BindingPriority.LocalValue)

View on GitHub (pinned to 11c5427268)

Solutions

  1. Bind using the concrete overload: target.Bind(StyledProperty<T>, source) or target.Bind(DirectPropertyBase<T>, source).
  2. Ensure the property is registered as styled or direct.
  3. Type-check before dispatching in generic helpers.

Example fix

// before
target.Bind(someProp, observable); // someProp is unknown kind

// after
switch (someProp)
{
    case StyledProperty<T> s: target.Bind(s, observable); break;
    case DirectPropertyBase<T> d: target.Bind(d, observable); break;
}
Defensive patterns

Strategy: type-guard

Validate before calling

switch (property)
{
    case StyledProperty<T> s: return target.Bind(s, source, priority);
    case DirectPropertyBase<T> d: return target.Bind(d, source);
    default: throw new NotSupportedException();
}

Type guard

static bool IsBindable<T>(AvaloniaProperty<T> p) =>
    p is StyledProperty<T> or DirectPropertyBase<T>;

Prevention

When it happens

Trigger: Passing a custom AvaloniaProperty<T> subclass, or an attached property not matching either branch, to the Bind overload taking BindingValue<T>.

Common situations: Generic/reflective binding helpers that resolve properties dynamically; libraries extending the property system.

Related errors


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