{"record":{"id":"8021e6f09b08db62","repo":"dotnet/wpf","slug":"sr-format-sr-markupextensionbadstatic-typenameforerror-is","errorCode":null,"errorMessage":"SR.Format(SR.MarkupExtensionBadStatic, typeNameForError is not null ? $\"{typeNameForError}.{_member}\" : _member)","messagePattern":"SR\\.Format\\(SR\\.MarkupExtensionBadStatic, typeNameForError is not null \\? \\$\"(.+?)\\.(.+?)\" : _member\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs","lineNumber":110,"sourceCode":"                if (string.IsNullOrEmpty(typeString))\n                {\n                    throw new ArgumentException(SR.Format(SR.MarkupExtensionBadStatic, _member));\n                }\n            }\n\n            // Use the built-in parser for enum types.\n            if (type.IsEnum)\n            {\n                return Enum.Parse(type, fieldString);\n            }\n\n            // For other types, reflect.\n            if (GetFieldOrPropertyValue(type, fieldString, out object value))\n            {\n                return value;\n            }\n\n            throw new ArgumentException(SR.Format(SR.MarkupExtensionBadStatic, typeNameForError is not null ? $\"{typeNameForError}.{_member}\" : _member));\n        }\n\n        /// <summary>\n        /// Return false if a public static field or property with the same\n        /// name cannot be found.\n        /// <summary>\n        private bool GetFieldOrPropertyValue(Type type, string name, out object value)\n        {\n            Type currentType = type;\n            do\n            {\n                FieldInfo field = currentType.GetField(name, BindingFlags.Public | BindingFlags.Static);\n                if (field is not null)\n                {\n                    value = field.GetValue(null);\n                    return true;\n                }\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/StaticExtension.cs#L92-L128","documentation":"After enum handling, StaticExtension uses reflection (GetFieldOrPropertyValue) to find a public static field or property named fieldString on the resolved type. If no such public static member exists (or its value is null), it throws MarkupExtensionBadStatic, reporting typeName.member (or the raw _member).","triggerScenarios":"ProvideValue where the type resolves but the member is not a public static field/property: wrong casing, instance member, private member, member that was renamed or removed, or a static member whose value is null.","commonSituations":"Renaming a constant without updating XAML {x:Static} references; referencing a protected/internal constant; version/library upgrades removing the member; typos in member names; targeting an enum value spelled incorrectly on a non-enum type.","solutions":["Verify the target type has a public static field or property with exactly that name (case-sensitive).","Use the enum name syntax for enum values ({x:Static ns:MyEnum.Value}) or ensure the type resolves to the enum.","Check the API version still exposes the member; add it back or point to its replacement.","Ensure the member is declared public; internal/protected statics are not visible."],"exampleFix":"// before\nText=\"{x:Static local:Constants.MaxRetries}\" // Constants has no public static MaxRetries\n// after\nText=\"{x:Static local:Constants.DefaultMaxRetries}\"","handlingStrategy":"try-catch","validationCode":"var flags = BindingFlags.Public | BindingFlags.Static;\nbool exists = type.GetField(memberName, flags) != null || type.GetProperty(memberName, flags) != null;","typeGuard":"static bool HasPublicStatic(Type t, string name) =>\n    t.GetField(name, BindingFlags.Public | BindingFlags.Static) != null ||\n    t.GetProperty(name, BindingFlags.Public | BindingFlags.Static) != null;","tryCatchPattern":"try { value = ext.ProvideValue(serviceProvider); } catch (ArgumentException ex) { /* member missing/renamed — fall back or fail the XAML load with a clear message */ }","preventionTips":["Keep XAML {x:Static} references in sync when renaming constants (use rename refactoring across XAML).","Only reference public static fields/properties.","After upgrading a referenced library, grep XAML for the old member name.","Use enum syntax {x:Static ns:Enum.Value} for enum values."],"tags":["xaml","reflection","static-member","argumentexception"],"backgroundTag":"resource-not-found","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"}