{"record":{"id":"c58471639124b0b9","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-member","errorCode":null,"errorMessage":"ArgumentNullException(nameof(member))","messagePattern":"ArgumentNullException\\(nameof\\(member\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs","lineNumber":37,"sourceCode":"    {\n        private string _member;\n        private Type _memberType;\n\n        /// <summary>\n        /// Constructor that takes no parameters\n        /// </summary>\n        public StaticExtension()\n        {\n        }\n\n        /// <summary>\n        /// Constructor that takes the member that this is a static reference to.\n        /// This string is of the format Prefix:ClassName.FieldOrPropertyName.\n        /// The Prefix is optional, and refers to the XML prefix in a Xaml file.\n        /// </summary>\n        public StaticExtension(string member)\n        {\n            _member = member ?? throw new ArgumentNullException(nameof(member));\n        }\n\n        /// <summary>\n        /// Return an object that should be set on the targetObject's targetProperty\n        /// for this markup extension. For a StaticExtension this is a static field\n        /// or property value.\n        /// </summary>\n        /// <param name=\"serviceProvider\">Object that can provide services for the markup extension.</param>\n        /// <returns> The object to set on this property.</returns>\n        public override object ProvideValue(IServiceProvider serviceProvider)\n        {\n            if (_member is null)\n            {\n                throw new InvalidOperationException(SR.MarkupExtensionStaticMember);\n            }\n\n            Type type = MemberType;\n            string fieldString;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs#L19-L55","documentation":"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.","triggerScenarios":"Calling new StaticExtension((string)null) — typically from reflective/generative code that resolves the member string dynamically and gets null.","commonSituations":"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.","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."],"exampleFix":"// before\nvar ext = new StaticExtension(config[\"member\"]); // config key missing → null\n// after\nvar member = config[\"member\"] ?? throw new InvalidOperationException(\"Static member not configured\");\nvar ext = new StaticExtension(member);","handlingStrategy":"validation","validationCode":"if (member is null) throw new ArgumentException(\"member string is required, e.g. 'ClassName.MemberName'\", nameof(member));\nvar ext = new StaticExtension(member);","typeGuard":"bool IsValidMemberString(string m) => m is not null;","tryCatchPattern":"try { var ext = new StaticExtension(member); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"member\") { /* handle missing member config */ }","preventionTips":["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."],"tags":["null-argument","constructor","xaml","markup-extension"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}