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
- Set Member before ProvideValue, ideally via the constructor: new StaticExtension("namespace:Type.Field").
- If parsing XAML, confirm the x:Static directive has a Member= attribute or positional argument.
- Guard with a null check on Member before calling ProvideValue to fail earlier with a clearer message.
- 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
- Prefer the string constructor new StaticExtension("ns:Type.Member") to force Member at construction.
- Centralize markup-extension construction in a helper that asserts required properties.
- Review XAML x:Static usages to confirm each has a Member operand.
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
- Member '{0}' could not be resolved to a static member
- Either TypeName or Type must be filled before calling Provid
- serviceProvider does not implement IXamlNameResolver
- typeName
- type
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/8c71d1de2cb45114.
Report an issue: GitHub.