{"record":{"id":"3001bc99ce980e8c","repo":"dotnet/wpf","slug":"sr-format-sr-markupextensionbadstatic-member-staticextension","errorCode":null,"errorMessage":"SR.Format(SR.MarkupExtensionBadStatic, _member)","messagePattern":"SR\\.Format\\(SR\\.MarkupExtensionBadStatic, _member\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs","lineNumber":68,"sourceCode":"            {\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                }\n\n                // Pull out the type substring (this will include any XML prefix, e.g. \"av:Button\")\n                string typeString = _member.Substring(0, dotIndex);\n                if (string.IsNullOrEmpty(typeString))\n                {\n                    throw new ArgumentException(SR.Format(SR.MarkupExtensionBadStatic, _member));\n                }\n\n                // Get the IXamlTypeResolver from the service provider\n\n                ArgumentNullException.ThrowIfNull(serviceProvider);\n\n                if (serviceProvider.GetService(typeof(IXamlTypeResolver)) is not IXamlTypeResolver xamlTypeResolver)\n                {\n                    throw new ArgumentException(SR.Format(SR.MarkupExtensionNoContext, GetType().Name, nameof(IXamlTypeResolver)));\n                }\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs#L50-L86","documentation":"StaticExtension (the XAML {x:Static} markup extension) resolves a 'Type.Member' string to a static field or property value via reflection. ProvideValue throws ArgumentException with MarkupExtensionBadStatic when the Member string contains no '.' separator, because it cannot be split into a type part and a member part. The library requires the format 'prefix:TypeName.MemberName' (prefix optional).","triggerScenarios":"Calling new StaticExtension(member).ProvideValue(serviceProvider) with a Member string that contains no dot, e.g. Member=\"Button\" or Member=\"\" — dotIndex = _member.IndexOf('.') is < 0.","commonSituations":"XAML files with {x:Static SomeValue} missing the type qualifier; code-built markup extensions where the member string was assembled from user input or config and the type portion was dropped; refactors that renamed types leaving a bare member name.","solutions":["Set Member to a fully qualified 'Type.Member' string, e.g. 'local:MyClass.MyConstant' or 'System:String.Empty'.","Validate the member string contains a '.' before calling ProvideValue.","In XAML, fix the {x:Static} usage to include the declaring type, e.g. {x:Static sys:String.Empty}.","If using an XML prefix, ensure the prefix is declared and the type part maps to the declaring type."],"exampleFix":"// before\nvar ext = new StaticExtension(\"MyConstant\");\n// after\nvar ext = new StaticExtension(\"MyNamespace.MyClass.MyConstant\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(member) || !member.Contains('.')) throw new ArgumentException($\"Member '{member}' must be in 'Type.Member' format\");","typeGuard":"static bool IsValidStaticMember(string? m) => !string.IsNullOrEmpty(m) && m.Contains('.');","tryCatchPattern":"try { value = ext.ProvideValue(serviceProvider); } catch (ArgumentException ex) { /* log ex.Message; surface XAML error */ }","preventionTips":["Always write {x:Static ns:Class.Member} with the declaring type.","Validate member strings contain a dot before constructing StaticExtension.","Prefer MemberType + typed code paths when the Type is already known."],"tags":["xaml","markup-extension","argumentexception","static-extension"],"backgroundTag":"invalid-argument-format","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"}