AvaloniaUI/Avalonia · error · NotSupportedException
Invalid BindingValueType.
Error message
Invalid BindingValueType.
What it means
Thrown as NotSupportedException by BindingValue<T>.ToObject() when the Type field does not match any known BindingValueType case in its switch expression (the default/_ arm). BindingValueType is a [Flags] enum; an unrecognized or corrupted flag combination that doesn't equal any named member triggers the default arm.
Source
Thrown at src/Avalonia.Base/Data/BindingValue.cs:166
/// appropriate.
/// </summary>
/// <returns>The untyped representation of the binding value.</returns>
public object? ToUntyped()
{
return Type switch
{
BindingValueType.UnsetValue => AvaloniaProperty.UnsetValue,
BindingValueType.DoNothing => BindingOperations.DoNothing,
BindingValueType.Value => _value,
BindingValueType.BindingError =>
new BindingNotification(Error!, BindingErrorType.Error),
BindingValueType.BindingErrorWithFallback =>
new BindingNotification(Error!, BindingErrorType.Error, Value),
BindingValueType.DataValidationError =>
new BindingNotification(Error!, BindingErrorType.DataValidationError),
BindingValueType.DataValidationErrorWithFallback =>
new BindingNotification(Error!, BindingErrorType.DataValidationError, Value),
_ => throw new NotSupportedException("Invalid BindingValueType."),
};
}
/// <summary>
/// Returns a new binding value with the specified value.
/// </summary>
/// <param name="value">The new value.</param>
/// <returns>The new binding value.</returns>
/// <exception cref="InvalidOperationException">
/// The binding type is <see cref="BindingValueType.UnsetValue"/> or
/// <see cref="BindingValueType.DoNothing"/>.
/// </exception>
public BindingValue<T> WithValue(T value)
{
if (Type == BindingValueType.DoNothing)
{
throw new InvalidOperationException("Cannot add value to DoNothing binding value.");
}View on GitHub (pinned to 11c5427268)
Solutions
- Always construct BindingValue<T> via its static factory methods (e.g., BindingValue<T>.FromValue, FromError) rather than the constructor, so Type is always valid.
- If you must construct directly, ensure Type is exactly one of the named BindingValueType members.
- Validate the Type against known members before calling ToObject().
Example fix
// before var bv = new BindingValue<T>((BindingValueType)999, value, null); var o = bv.ToObject(); // throws // after var bv = BindingValue<T>.FromValue(value); // factory sets a valid Type
Defensive patterns
Strategy: validation
Validate before calling
var known = bv.Type is BindingValueType.UnsetValue or BindingValueType.DoNothing
or BindingValueType.Value or BindingValueType.BindingError
or BindingValueType.BindingErrorWithFallback
or BindingValueType.DataValidationError or BindingValueType.DataValidationErrorWithFallback;
if (known) var o = bv.ToObject(); Type guard
static bool IsValidType(BindingValueType t) =>
t is BindingValueType.UnsetValue or BindingValueType.DoNothing or BindingValueType.Value
or BindingValueType.BindingError or BindingValueType.BindingErrorWithFallback
or BindingValueType.DataValidationError or BindingValueType.DataValidationErrorWithFallback; Try / catch
try { var o = bv.ToObject(); }
catch (NotSupportedException ex) when (ex.Message.Contains("Invalid BindingValueType"))
{ /* log:BindingValue constructed with invalid Type; use a factory method */ } Prevention
- Always build BindingValue<T> via static factory methods, never the constructor.
- Validate Type against known members before ToObject().
- Treat this exception as a defect indicator, not a runtime path.
When it happens
Trigger: BindingValue<T> is constructed directly (bypassing the static factory methods) with a Type value that is not one of UnsetValue, DoNothing, Value, BindingError, BindingErrorWithFallback, DataValidationError, DataValidationErrorWithFallback. Also theoretically reachable if reflection/binary deserialization produces an invalid enum.
Common situations: Internal/advanced code manually constructing BindingValue<T> with an invalid Type. Deserialization corruption. Unreleased enum member not handled by the switch. This is a defensive guard; normal factory APIs never produce this.
Related errors
- BindingValue has no value.
- Cannot add value to DoNothing binding value.
- Object of type '{value?.GetType()}' cannot be converted to t
- Value must be less than 10.
- Give me 5 or more letter please :-)
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/79bafc500c64f71e.
Report an issue: GitHub.