unoplatform/uno · error · NotSupportedException

not supported operation on directive member {0}

Error message

not supported operation on directive member {0}

What it means

Thrown by XamlMemberInvoker.GetValue/SetValue when the member is a XamlDirective (e.g. x:Name, x:Key, or other directive members) rather than a real CLR member. Directives have no underlying getter/setter MethodInfo, so invoking them via reflection is unsupported.

Source

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

		}

		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});
		}

View on GitHub (pinned to 0418340488)

Solutions

  1. Check member is XamlDirective before invoking and dispatch to directive-specific handling (e.g. name registration, resource-key assignment).
  2. Filter directive members out of the normal property-set loop in your object writer.
  3. Use XamlMember.Invoker only for non-directive members.

Example fix

// before
foreach (var m in members)
    m.Invoker.SetValue(instance, value); // throws on x:Name

// after
foreach (var m in members)
{
    if (m is XamlDirective) { HandleDirective(m, instance, value); continue; }
    m.Invoker.SetValue(instance, value);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (member is XamlDirective)
{
    HandleDirective(member, instance, value);
    return;
}
invoker.SetValue(instance, value);

Type guard

static bool IsDirective(XamlMember m) => m is XamlDirective;

Prevention

When it happens

Trigger: A XAML processor routes a directive member through GetValue/SetValue. This can happen when an invoker is fetched for a directive member and the generic get/set path is taken instead of the directive-specific handler.

Common situations: Custom XAML object writers that handle all members uniformly without checking IsDirective; schema contexts that wrap directives in invokers; misrouting of x:Name/x:Key handling.

Related errors


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