dotnet/wpf · error · ArgumentNullException

ArgumentNullException(nameof(value))

Error message

ArgumentNullException(nameof(value))

What it means

The StaticExtension.Member property setter rejects null with ArgumentNullException because the Member string is the core payload of the extension (marked [ConstructorArgument("member")]). The member path must always be a non-null string, even if it may later prove malformed.

Solutions

  1. Pass a non-null 'Type.Member' string to the constructor or Member setter.
  2. Coalesce nulls at the call site: new StaticExtension(member ?? fallback).
  3. Check earlier parsing/config code that produced the null member string.

Example fix

// before
var ext = new StaticExtension(GetMemberName()); // may return null
// after
var ext = new StaticExtension(GetMemberName() ?? "MyNamespace.MyClass.MyConstant");
Defensive patterns

Strategy: validation

Validate before calling

if (member is null) throw new InvalidOperationException("StaticExtension.Member cannot be null");

Type guard

static bool IsValidMember(string? m) => m is not null;

Try / catch

try { ext.Member = candidate; } catch (ArgumentNullException) { /* supply default or abort */ }

Prevention

When it happens

Trigger: Assigning ext.Member = null, or calling new StaticExtension(null) — the constructor delegates to the Member setter.

Common situations: Deserializing markup extension settings where the member value is missing; conditional code passing a variable that is null; data-bound config strings that failed to load.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/5465993b1b4a01d5. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs:160

                currentType = currentType.BaseType;
            }
            while (currentType is not null);

            value = null;
            return false;
        }

        /// <summary>
        /// The static field or property represented by a string. This string is
        /// of the format Prefix:ClassName.FieldOrPropertyName. The Prefix is
        /// optional, and refers to the XML prefix in a Xaml file.
        /// </summary>
        [ConstructorArgument("member")]
        public string Member
        {
            get => _member;
            set => _member = value ?? throw new ArgumentNullException(nameof(value));
        }

        [DefaultValue(null)]
        public Type MemberType
        {
            get => _memberType;
            set => _memberType = value ?? throw new ArgumentNullException(nameof(value));
        }
    }
}

View on GitHub (pinned to 81131a70a4)