unoplatform/uno · error · NotSupportedException

Attempt to get value from write-only property or event {0}

Error message

Attempt to get value from write-only property or event {0}

What it means

Thrown by XamlMemberInvoker.GetValue when the member is known and non-directive but has no UnderlyingGetter — i.e. it is write-only (a set-only property) or an event (events have no getter). Reading such a member has no CLR method to invoke.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlMemberInvoker.cs:72

		public MethodInfo UnderlyingSetter {
			get { return member != null ? member.UnderlyingSetter : null; }
		}

		void ThrowIfUnknown ()
		{
			if (member == null)
				throw new NotSupportedException ("Current operation is invalid for unknown member.");
		}

		public virtual object GetValue (object instance)
		{
			ThrowIfUnknown ();
			if (instance == null)
				throw new ArgumentNullException ("instance");
			if (member is XamlDirective)
				throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "not supported operation on directive member {0}", member));
			if (UnderlyingGetter == null)
				throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Attempt to get value from write-only property or event {0}", member));
			return UnderlyingGetter.Invoke (instance, Array.Empty<object>());
		}
		public virtual void SetValue (object instance, object value)
		{
			ThrowIfUnknown ();
			if (instance == null)
				throw new ArgumentNullException ("instance");
			if (member is XamlDirective)
				throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "not supported operation on directive member {0}", member));
			if (UnderlyingSetter == null)
				throw new NotSupportedException (String.Format (CultureInfo.InvariantCulture, "Attempt to set value from read-only property {0}", member));
			if (member.IsAttachable)
				UnderlyingSetter.Invoke (null, new object [] {instance, value});
			else
				UnderlyingSetter.Invoke (instance, new object [] {value});
		}

		public virtual ShouldSerializeResult ShouldSerializeValue (object instance)

View on GitHub (pinned to 0418340488)

Solutions

  1. Check member.UnderlyingGetter != null (or member.IsReadVisible / IsReadable) before calling GetValue.
  2. Skip write-only and event members during serialization.
  3. Mark the property with [DesignerSerializationVisibility(Hidden)] to exclude it from serialization.

Example fix

// before
var v = invoker.GetValue(instance); // throws for set-only

// after
if (invoker.UnderlyingGetter != null)
    var v = invoker.GetValue(instance);
Defensive patterns

Strategy: type-guard

Validate before calling

if (invoker.UnderlyingGetter == null)
{
    // write-only or event; cannot read
    return;
}
var v = invoker.GetValue(instance);

Type guard

static bool IsReadable(XamlMember m) => m != null && m.UnderlyingGetter != null;

Prevention

When it happens

Trigger: Calling GetValue on an invoker whose XamlMember.UnderlyingGetter is null. Occurs for set-only properties, event members, or members backed only by add/remove handlers.

Common situations: Generic XAML round-tripping that attempts to serialize every member including write-only ones; serializers that do not check readability; binding code that reads a property not meant to be read.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/5771cfa2a5008c1f. Report an issue: GitHub.