dotnet/wpf · error · NotSupportedException
Cannot get write-only property
Error message
Cannot get write-only property '{0}'. What it means
DynamicMethodRuntime.GetValue is called to read a member's value, but the member's invoker has no UnderlyingGetter (the property is write-only). It throws NotSupportedException with CantGetWriteonlyProperty ('Cannot get a write-only property {0}'). The library throws this because there is no getter method to invoke for the property.
Solutions
- Add a public getter to the property, or make it read-write if serialization requires round-tripping
- Exclude the write-only property from XAML by making it internal/private or marking the type appropriately for the schema
- Use a different member (read-only wrapper or attached representation) to convey the value in XAML
Example fix
// before
public string Secret { set { _secret = value; } }
// after
public string Secret { get; set; } Defensive patterns
Strategy: try-catch
Validate before calling
static void EnsureReadable(Type t, string prop) { var p = t.GetProperty(prop); if (p != null && p.GetMethod == null) throw new InvalidOperationException($"{t}.{prop} is write-only and cannot be XAML-read"); } Type guard
static bool IsXamlReadable(System.Reflection.PropertyInfo p) => p?.GetMethod is { IsPublic: true }; Try / catch
try { Save(obj); } catch (NotSupportedException ex) when (ex.Message.Contains("write-only property")) { throw new InvalidOperationException($"Exclude write-only member: {ex.Message}", ex); } Prevention
- Audit serializable types for set-only properties before enabling XAML save
- Make password/secret properties internal and exclude them from schema
- Prefer read-write properties on XAML-visible types
When it happens
Trigger: XAML load or save attempts to read (get) a member whose CLR property defines only a setter — e.g. XamlXmlWriter or XamlObjectWriter querying a write-only property, or a positional/mapped member whose getter is missing.
Common situations: Objects with write-only properties (e.g. password fields) included in XAML-serializable types; WPF dependency properties or wrappers exposing only setters; schema/type mapping pointing at a property without a getter.
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
- Cannot set read-only property
- Cannot get a XamlDeferringLoader from XamlValueConverter
- ' '.' ' is a property without a getter and is not a valid…
- ' '.' ' is a property without a getter and is not a valid…
- ' '.' ' is a property without a getter and is not a valid…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ee9702e458ded977.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs:243
protected override object InvokeFactoryMethod(Type type, string methodName, object[] args)
{
MethodInfo factory = GetFactoryMethod(type, methodName, args, BF_AllStaticMembers);
FactoryDelegate factoryDelegate;
if (!FactoryDelegates.TryGetValue(factory, out factoryDelegate))
{
factoryDelegate = CreateFactoryDelegate(factory);
FactoryDelegates.Add(factory, factoryDelegate);
}
return factoryDelegate.Invoke(args);
}
protected override object GetValue(XamlMember member, object obj)
{
MethodInfo getter = member.Invoker.UnderlyingGetter;
if (getter is null)
{
throw new NotSupportedException(SR.Format(SR.CantGetWriteonlyProperty, member));
}
PropertyGetDelegate getterDelegate;
if (!PropertyGetDelegates.TryGetValue(getter, out getterDelegate))
{
getterDelegate = CreateGetDelegate(getter);
PropertyGetDelegates.Add(getter, getterDelegate);
}
return getterDelegate.Invoke(obj);
}
protected override void SetValue(XamlMember member, object obj, object value)
{
MethodInfo setter = member.Invoker.UnderlyingSetter;
if (setter is null)
{
throw new NotSupportedException(SR.Format(SR.CantSetReadonlyProperty, member));View on GitHub (pinned to 81131a70a4)