dotnet/wpf · error · ArgumentNullException
ArgumentNullException(nameof(member))
Error message
ArgumentNullException(nameof(member))
What it means
StaticExtension's string-taking constructor throws ArgumentNullException when the member argument is null. The member string (format Prefix:ClassName.FieldOrPropertyName) is the core state of the extension, so null is rejected immediately at construction. This is eager argument validation consistent with ArrayExtension's constructor guard.
Solutions
- Pass a non-null member string such as "ClassName.PropertyName" to the constructor.
- Validate the source string for null before constructing the extension and surface a clearer error at that point.
- Use the parameterless StaticExtension() constructor plus Member/MemberType assignment if constructing in stages.
Example fix
// before
var ext = new StaticExtension(config["member"]); // config key missing → null
// after
var member = config["member"] ?? throw new InvalidOperationException("Static member not configured");
var ext = new StaticExtension(member); Defensive patterns
Strategy: validation
Validate before calling
if (member is null) throw new ArgumentException("member string is required, e.g. 'ClassName.MemberName'", nameof(member));
var ext = new StaticExtension(member); Type guard
bool IsValidMemberString(string m) => m is not null;
Try / catch
try { var ext = new StaticExtension(member); }
catch (ArgumentNullException ex) when (ex.ParamName == "member") { /* handle missing member config */ } Prevention
- Source the member string from validated configuration, never raw dictionary lookups.
- Assert member is non-null in factories that build StaticExtension instances.
- For generated code, emit the member string only when the source attribute was present.
When it happens
Trigger: Calling new StaticExtension((string)null) — typically from reflective/generative code that resolves the member string dynamically and gets null.
Common situations: Code generators or XAML infrastructure emitting StaticExtension where the member attribute was absent; config-driven construction where the 'member' key is missing and yields null; tests exercising null-argument contracts.
Related errors
- ArgumentNullException(nameof(arrayType))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
- ArgumentNullException(nameof(newNamespace))
- ArgumentNullException(nameof(oldNamespace))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c58471639124b0b9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs:37
{
private string _member;
private Type _memberType;
/// <summary>
/// Constructor that takes no parameters
/// </summary>
public StaticExtension()
{
}
/// <summary>
/// Constructor that takes the member that this is a static reference to.
/// This string is of the format Prefix:ClassName.FieldOrPropertyName.
/// The Prefix is optional, and refers to the XML prefix in a Xaml file.
/// </summary>
public StaticExtension(string member)
{
_member = member ?? throw new ArgumentNullException(nameof(member));
}
/// <summary>
/// Return an object that should be set on the targetObject's targetProperty
/// for this markup extension. For a StaticExtension this is a static field
/// or property value.
/// </summary>
/// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
/// <returns> The object to set on this property.</returns>
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (_member is null)
{
throw new InvalidOperationException(SR.MarkupExtensionStaticMember);
}
Type type = MemberType;
string fieldString;View on GitHub (pinned to 81131a70a4)