AvaloniaUI/Avalonia · error · NotSupportedException
Property {Name} doesn't have a getter
Error message
Property {Name} doesn't have a getter What it means
ClrPropertyInfo wraps a CLR property's getter and setter delegates. Get() throws NotSupportedException when the property was constructed with a null getter, i.e. the property is write-only (set accessor only). Avalonia binds by reading the property, so a write-only property cannot supply a value.
Source
Thrown at src/Avalonia.Base/Data/Core/ClrPropertyInfo.cs:25
{
private readonly Func<object, object?>? _getter;
private readonly Action<object, object?>? _setter;
public ClrPropertyInfo(string name, Func<object, object?>? getter, Action<object, object?>? setter, Type propertyType)
{
_getter = getter;
_setter = setter;
PropertyType = propertyType;
Name = name;
}
public string Name { get; }
public Type PropertyType { get; }
public object? Get(object target)
{
if (_getter == null)
throw new NotSupportedException("Property " + Name + " doesn't have a getter");
return _getter(target);
}
public void Set(object target, object? value)
{
if (_setter == null)
throw new NotSupportedException("Property " + Name + " doesn't have a setter");
_setter(target, value);
}
public bool CanSet => _setter != null;
public bool CanGet => _getter != null;
}
public class ReflectionClrPropertyInfo : ClrPropertyInfo
{
private static Action<object, object?>? CreateSetter(PropertyInfo info)
=> info.SetMethod is { } setMethod ?View on GitHub (pinned to 11c5427268)
Solutions
- Add a getter to the bound property (`public int X { get; set; }`).
- Repoint the binding to a different property that is readable.
- If using OneWayToSource only, ensure the binding direction is actually source-bound and you never read the target property.
Example fix
// before
public string Secret { set; }
<TextBlock Text="{Binding Secret}" />
// after
public string Secret { get; set; } Defensive patterns
Strategy: type-guard
Validate before calling
// Check CanGet before reading via ClrPropertyInfo.
if (propertyInfo is ClrPropertyInfo clr && !clr.CanGet)
throw new InvalidOperationException($"{clr.Name} is write-only and cannot be read.");
var value = propertyInfo.Get(target); Type guard
static bool IsReadable(ClrPropertyInfo p) => p.CanGet;
Try / catch
try { return propertyInfo.Get(target); }
catch (NotSupportedException) { /* property has no getter */ return AvaloniaProperty.UnsetValue; } Prevention
- Prefer get/set auto-properties for bindable viewmodel members.
- When reflecting, filter out write-only members before binding.
- Keep a test binding each read-only-vs-write-only path.
When it happens
Trigger: Binding (reading direction) to a CLR property that only has a setter. Occurs when reflection or an explicit ClrPropertyInfo is created from a write-only member and then the binding engine calls Get().
Common situations: Binding a control to a viewmodel property declared as `public int X { set; }`; password-style write-only fields; refactoring a property to remove its getter while a binding still targets it.
Related errors
- Property {Name} doesn't have a setter
- Could not convert list index '{i}' of type '{argument}' to '
- Invalid method handle
- Unexpected null returned from Type.GetTypeFromHandle in Meth
- Two way bindings are not supported with a string format
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/b8334eb3ed7675de.
Report an issue: GitHub.