unoplatform/uno · error · InvalidOperationException

Member property must be set to StaticExtension before callin

Error message

Member property must be set to StaticExtension before calling ProvideValue method.

What it means

Thrown by StaticExtension (x:Static) when ProvideValue is called before its Member property has been assigned. Member is the required, constructor-argument-backed string that identifies which static member to return, so the extension cannot produce a value without it.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Windows.Markup/StaticExtension.cs:58

		{
		}

		public StaticExtension (string member)
		{
			Member = member;
		}

		[ConstructorArgument ("member")]
		public string Member { get; set; }

		[DefaultValue (null)]
		public Type MemberType { get; set; }

		public override object ProvideValue (IServiceProvider serviceProvider)
		{
			if (Member == null)
			{
				throw new InvalidOperationException ("Member property must be set to StaticExtension before calling ProvideValue method.");
			}

			if (MemberType != null) {
				var pi = MemberType.GetProperty (Member, BindingFlags.Public | BindingFlags.Static);
				if (pi != null)
				{
					return pi.GetValue (null, null);
				}

				var fi = MemberType.GetField (Member, BindingFlags.Public | BindingFlags.Static);
				if (fi != null)
				{
					return fi.GetValue (null);
				}
			}
			// there might be some cases that it could still
			// resolve a static member without MemberType, 
			// but we don't know any of such so far.

View on GitHub (pinned to 0418340488)

Solutions

  1. Set Member before ProvideValue, ideally via the constructor: new StaticExtension("namespace:Type.Field").
  2. If parsing XAML, confirm the x:Static directive has a Member= attribute or positional argument.
  3. Guard with a null check on Member before calling ProvideValue to fail earlier with a clearer message.
  4. Ensure your XAML namespace prefixes are declared so the Member string can be parsed.

Example fix

// before
var ext = new StaticExtension();
var v = ext.ProvideValue(sp); // throws

// after
var ext = new StaticExtension("sys:Math.PI");
var v = ext.ProvideValue(sp);
Defensive patterns

Strategy: validation

Validate before calling

var ext = new StaticExtension();
// ... possibly set other props ...
if (ext.Member == null)
    throw new InvalidOperationException("Set Member before ProvideValue");
var value = ext.ProvideValue(sp);

Type guard

static bool IsStaticExtensionReady(StaticExtension e) => !string.IsNullOrEmpty(e.Member);

Prevention

When it happens

Trigger: Instantiating StaticExtension and calling ProvideValue without setting Member (or without using the string constructor). Programmatic construction with the parameterless ctor followed by immediate ProvideValue.

Common situations: Custom XAML pre-processors that build markup extensions imperatively; copy-paste mistakes where Member was set on a different instance; deserialization paths that skip required property binding.

Related errors


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