dotnet/wpf · error · NotSupportedException
SR.CantGetWriteonlyProperty
Error message
SR.CantGetWriteonlyProperty
What it means
XamlMemberInvoker.GetValue reads the member's value via its underlying getter. When the member has no getter (write-only property or unknown accessor), NotSupportedException with SR.CantGetWriteonlyProperty (formatted with the member) is thrown, because there is no way to produce a value.
Solutions
- Check `invoker.UnderlyingGetter is null` (or member.IsReadPublic / CanRead) before calling GetValue and skip or log instead.
- Wrap in try-catch for NotSupportedException if member readability cannot be determined statically.
- If read access is genuinely required, add a getter to the property or use the backing field/storage directly.
Example fix
// before
foreach (var m in type.GetAllMembers()) values[m.Name] = m.Invoker.GetValue(obj); // throws on write-only
// after
foreach (var m in type.GetAllMembers())
{
if (m.Invoker.UnderlyingGetter is not null)
values[m.Name] = m.Invoker.GetValue(obj);
} Defensive patterns
Strategy: type-guard
Validate before calling
bool canRead = member.Invoker.UnderlyingGetter is not null;
Type guard
static bool CanRead(XamlMember m) => m.Invoker.UnderlyingGetter is not null;
Try / catch
try { value = invoker.GetValue(instance); }
catch (NotSupportedException) { /* write-only member: skip */ } Prevention
- Check CanRead/UnderlyingGetter before any generic GetValue call
- Skip members without getters in serialization/dump code
- Know which attached properties are set-only in your schemas
When it happens
Trigger: Calling invoker.GetValue(instance) where the XamlMember wraps a write-only property (setter only, UnderlyingGetter is null); also invoked by member.UnknownInvoker paths.
Common situations: Generic property-walking code (dumpers, serializers, diff tools) that calls GetValue on every member without checking whether it is readable; attached properties defined with only a setter.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.CantSetReadonlyProperty
- SR.NotSupportedOnDirective
- SR.NotSupportedOnUnknownMember
- SR.OnlySupportedOnCollections
- CollectionIsFixedSize
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d29af14e9be01285.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs:57
}
public MethodInfo UnderlyingGetter
{
get { return IsUnknown ? null : _member.Getter; }
}
public MethodInfo UnderlyingSetter
{
get { return IsUnknown ? null : _member.Setter; }
}
public virtual object GetValue(object instance)
{
ArgumentNullException.ThrowIfNull(instance);
ThrowIfUnknown();
if (UnderlyingGetter is null)
{
throw new NotSupportedException(SR.Format(SR.CantGetWriteonlyProperty, _member));
}
if (UnderlyingGetter.IsStatic)
{
return UnderlyingGetter.Invoke(null, new object[] { instance });
}
else
{
return UnderlyingGetter.Invoke(instance, Array.Empty<object>());
}
}
public virtual void SetValue(object instance, object value)
{
ArgumentNullException.ThrowIfNull(instance);
ThrowIfUnknown();
if (UnderlyingSetter is null)
{View on GitHub (pinned to 81131a70a4)