{"record":{"id":"79d1dd20228ecbea","repo":"dotnet/wpf","slug":"sr-markupextensionstaticmember-staticextension","errorCode":null,"errorMessage":"SR.MarkupExtensionStaticMember","messagePattern":"SR\\.MarkupExtensionStaticMember","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs","lineNumber":51,"sourceCode":"        /// 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;\n            string typeNameForError = null;\n            if (type is not null)\n            {\n                fieldString = _member;\n                typeNameForError = type.FullName;\n            }\n            else\n            {\n                // Validate the _member\n                int dotIndex = _member.IndexOf('.');\n                if (dotIndex < 0)\n                {\n                    throw new ArgumentException(SR.Format(SR.MarkupExtensionBadStatic, _member));\n                }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs#L33-L69","documentation":"StaticExtension.ProvideValue throws InvalidOperationException (SR.MarkupExtensionStaticMember) when the internal _member field is null. This occurs when the extension was built with the parameterless constructor and neither Member nor MemberType was ever assigned. ProvideValue needs the member (or a MemberType + member string) to locate the static field/property value.","triggerScenarios":"Calling ProvideValue on a StaticExtension created with the parameterless constructor where Member was never set (e.g. new StaticExtension().ProvideValue(provider)).","commonSituations":"Programmatic XAML construction skipping the Member assignment; markup extension evaluation frameworks that instantiate extensions via the default constructor and expect deferred property population that never happens.","solutions":["Set the Member property (e.g. \"System.Math.PI\") or use the StaticExtension(string) constructor before calling ProvideValue.","Alternatively set MemberType plus the member name when using the MemberType-based resolution path.","Guard: check extension.Member for null and fail fast in your own code before invoking ProvideValue."],"exampleFix":"// before\nvar ext = new StaticExtension();\nvar v = ext.ProvideValue(provider); // throws\n// after\nvar ext = new StaticExtension { Member = \"System.Math.PI\" };\nvar v = ext.ProvideValue(provider);","handlingStrategy":"type-guard","validationCode":"if (ext.Member is null && ext.MemberType is null)\n    throw new InvalidOperationException(\"StaticExtension requires Member (or MemberType + member) before ProvideValue\");","typeGuard":"bool CanProvideStaticValue(StaticExtension ext) => ext is not null && ext.Member is not null;","tryCatchPattern":"try { var v = ext.ProvideValue(provider); }\ncatch (InvalidOperationException) { /* Member unset — initialize and retry or fail with context */ }","preventionTips":["Prefer the StaticExtension(string) constructor so Member is always set.","In deferred-construction scenarios, set Member/MemberType in the same step that instantiates the extension.","Add a debug assertion that Member is non-null before any ProvideValue call site."],"tags":["invalid-state","xaml","markup-extension","uninitialized"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}