AvaloniaUI/Avalonia · error · NotSupportedException
Unsupported AvaloniaProperty type.
Error message
Unsupported AvaloniaProperty type.
What it means
Thrown by AvaloniaObject.ClearValue<T> when the supplied property is neither a StyledProperty<T> nor a DirectPropertyBase<T>. The generic ClearValue dispatches on the runtime property kind; any other AvaloniaProperty subclass (or an untyped/registered-as-other property) hits the default branch.
Source
Thrown at src/Avalonia.Base/AvaloniaObject.cs:157
/// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
/// </summary>
/// <param name="property">The property.</param>
public void ClearValue<T>(AvaloniaProperty<T> property)
{
ThrowHelper.ThrowIfNull(property, nameof(property));
VerifyAccess();
switch (property)
{
case StyledProperty<T> styled:
ClearValue(styled);
break;
case DirectPropertyBase<T> direct:
ClearValue(direct);
break;
default:
throw new NotSupportedException("Unsupported AvaloniaProperty type.");
}
}
/// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
/// </summary>
/// <param name="property">The property.</param>
public void ClearValue<T>(StyledProperty<T> property)
{
ThrowHelper.ThrowIfNull(property, nameof(property));
VerifyAccess();
_values.ClearValue(property);
}
/// <summary>
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
/// </summary>View on GitHub (pinned to 11c5427268)
Solutions
- Use the property-type-specific overload: ClearValue(StyledProperty<T>) or ClearValue(DirectPropertyBase<T>).
- Cast the property to its concrete type before clearing.
- For attached properties, use the static ClearValue(provider, AttachedProperty) helper on the owning type.
Example fix
// before
obj.ClearValue((AvaloniaProperty<double>)someUnknownProp);
// after
if (someUnknownProp is StyledProperty<double> styled)
obj.ClearValue(styled);
else if (someUnknownProp is DirectPropertyBase<double> direct)
obj.ClearValue(direct); Defensive patterns
Strategy: type-guard
Validate before calling
switch (property)
{
case StyledProperty<T> s: obj.ClearValue(s); break;
case DirectPropertyBase<T> d: obj.ClearValue(d); break;
default: throw new NotSupportedException();
} Type guard
static bool IsClearable(AvaloniaProperty<T> p) =>
p is StyledProperty<T> or DirectPropertyBase<T>; Prevention
- Prefer the concrete-typed ClearValue overloads.
- In generic code, switch on the property runtime type.
When it happens
Trigger: Calling ClearValue<T> with a property instance whose runtime type is a custom AvaloniaProperty subclass; passing an AttachedProperty that does not derive from StyledProperty<T>; calling the wrong generic arity.
Common situations: Reflection-based code that resolves an AvaloniaProperty by name and calls ClearValue generically; mixing styled and direct property APIs.
Related errors
- Binding returned unsupported {nameof(BindingExpressionBase)}
- The property {property.Name} is readonly.
- Unsupported AvaloniaProperty type.
- Invalid priority ${priority}
- 'name' may not contain periods.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/dfeda7f9e59dd903.
Report an issue: GitHub.