AvaloniaUI/Avalonia · error · ArgumentException
Invalid priority ${priority}
Error message
Invalid priority ${priority} What it means
Thrown by ThrowInvalidPriority when a binding priority is outside the valid range [BindingPriority.Animation, BindingPriority.Inherited). Note: the message contains a literal '${priority}' due to an interpolation bug in the source ($ followed by {priority} instead of {priority}), so the actual priority value is NOT shown in the exception text. Priority must fall within the defined BindingPriority enum band.
Source
Thrown at src/Avalonia.Base/AvaloniaObject.cs:894
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void ValidatePriority(BindingPriority priority)
{
if (priority < BindingPriority.Animation || priority >= BindingPriority.Inherited)
ThrowInvalidPriority(priority);
}
private static void ThrowIfReadOnly(AvaloniaProperty property)
{
if (property.IsReadOnly)
{
throw new ArgumentException($"The property {property.Name} is readonly.");
}
}
private static void ThrowInvalidPriority(BindingPriority priority)
{
throw new ArgumentException($"Invalid priority ${priority}", nameof(priority));
}
}
}
View on GitHub (pinned to 11c5427268)
Solutions
- Use one of the named BindingPriority values (Animation, LocalValue, StyleTrigger, etc.) rather than raw ints.
- Validate priority with the same bounds check (>= Animation && < Inherited) before calling.
- If you see literal '${priority}' in the message, note it is a known formatting defect; inspect the priority argument in a debugger.
Example fix
// before obj.SetValue(MyProp, value, (BindingPriority)999); // after obj.SetValue(MyProp, value, BindingPriority.LocalValue);
Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidPriority(BindingPriority p) =>
p >= BindingPriority.Animation && p < BindingPriority.Inherited; Try / catch
try { obj.SetValue(prop, value, priority); }
catch (ArgumentException ex) when (ex.Message.Contains("Invalid priority"))
{ obj.SetValue(prop, value, BindingPriority.LocalValue); } Prevention
- Use named BindingPriority values, not raw ints.
- Validate the band before calling; remember the message has a formatting bug.
When it happens
Trigger: Calling SetValue/Bind with a BindingPriority value outside the allowed band; casting an arbitrary int to BindingPriority and passing it.
Common situations: Custom binding code that hand-picks a priority; passing default(BindingPriority) in a path that expects a concrete level; numeric coercion bugs.
Related errors
- The property {property.Name} is readonly.
- Unsupported AvaloniaProperty type.
- 'name' may not contain periods.
- Object of type '{value?.GetType()}' cannot be converted to t
- Value must be less than 10.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/f59bb1e6c289d47d.
Report an issue: GitHub.