AvaloniaUI/Avalonia · error · ArgumentException
The property {property.Name} is readonly.
Error message
The property {property.Name} is readonly. What it means
Thrown by AvaloniaObject.ThrowIfReadOnly when attempting to write a property whose IsReadOnly flag is set. ReadOnly properties (typically registered with RegisterReadOnly and exposing only a public getter) reject local writes and bindings.
Source
Thrown at src/Avalonia.Base/AvaloniaObject.cs:888
}
else
{
builder.Append(ToString());
}
}
[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
- Do not bind or set read-only properties; use the control's API that internally updates them.
- If you own the property and need external writes, register it as read-write or expose a protected setter key.
- In XAML/styles, remove setters that target read-only properties.
Example fix
// before control.SetValue(Visual.BoundsProperty, new Rect(...)); // Bounds is read-only // after // drive the bounds through layout, not by setting the property control.InvalidateMeasure();
Defensive patterns
Strategy: validation
Validate before calling
if (property.IsReadOnly)
throw new InvalidOperationException($"{property.Name} is read-only; use the control API instead"); Type guard
static bool IsWritable(AvaloniaProperty p) => !p.IsReadOnly;
Try / catch
try { obj.SetValue(property, value); }
catch (ArgumentException ex) when (ex.Message.Contains("readonly"))
{ /* cannot write; adjust caller */ } Prevention
- Check property.IsReadOnly before binding/setting in generic code.
- Drive read-only properties through their owning control's methods.
When it happens
Trigger: Calling SetValue/Bind on a ReadOnlyProperty; XAML or styling trying to assign a value to a read-only property; a style setter targeting a read-only property.
Common situations: Confusing a read-only property (computed/managed by the control) with a settable one; targeting properties like Visual.Bounds or control computed-state in styles.
Related errors
- Unsupported AvaloniaProperty type.
- Invalid priority ${priority}
- 'name' may not contain periods.
- The property {Name} is readonly.
- Transition elements have different parents.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/b75b6143171b3aa8.
Report an issue: GitHub.