{"record":{"id":"c40ac8bb85e2751f","repo":"dotnet/wpf","slug":"sr-format-sr-settervalueofmarkupextensionnotsupported-value","errorCode":null,"errorMessage":"SR.Format(SR.SetterValueOfMarkupExtensionNotSupported, value.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.SetterValueOfMarkupExtensionNotSupported, value\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs","lineNumber":112,"sourceCode":"            {\n                // Setter on container is not allowed to affect the StyleProperty.\n                if (dp == FrameworkElement.StyleProperty)\n                {\n                    throw new ArgumentException(SR.StylePropertyInStyleNotAllowed);\n                }\n            }\n\n            // Value needs to be valid for the DP, or a deferred reference, or one of the supported\n            // markup extensions.\n\n            if (!dp.IsValidValue(value))\n            {\n                // The only markup extensions supported by styles is resources and bindings.\n                if (value is MarkupExtension)\n                {\n                    if ( !(value is DynamicResourceExtension) && !(value is System.Windows.Data.BindingBase) )\n                    {\n                        throw new ArgumentException(SR.Format(SR.SetterValueOfMarkupExtensionNotSupported,\n                                                           value.GetType().Name));\n                    }\n                }\n\n                else if (!(value is DeferredReference))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidSetterValue, value, dp.OwnerType, dp.Name));\n                }\n            }\n\n            // Freeze the value for the setter\n            StyleHelper.SealIfSealable(_value);\n\n            base.Seal();\n        }\n\n        /// <summary>\n        ///    Property that is being set by this setter","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs#L94-L130","documentation":"Styles only support DynamicResourceExtension and BindingBase-derived markup extensions as Setter values. During Seal(), WPF throws this ArgumentException if the setter's value is any other MarkupExtension (e.g. StaticResource is resolved earlier, but extensions like x:Static wrappers, TemplateBinding via code, or custom markup extensions are rejected).","triggerScenarios":"Setting a Setter's value in code to a custom MarkupExtension instance or an unsupported extension (anything not DynamicResourceExtension or BindingBase), then applying the style.","commonSituations":"Programmatic style construction passing a custom MarkupExtension; porting XAML patterns to C# where the XAML compiler would have resolved the extension; using extensions like ThemeResource-like custom providers in code.","solutions":["Replace the custom extension value with its computed value, or use DynamicResourceExtension/Binding instead.","Resolve the extension yourself (e.g. ProvideValue or fetch the resource) before assigning to the Setter's Value.","If deferred/binding semantics are needed, use `new Binding { Source = ... }` or `new DynamicResourceExtension(resourceKey)`."],"exampleFix":"// before\nsetter.Value = new MyCustomExtension();\n// after\nsetter.Value = new DynamicResourceExtension(\"MyResourceKey\");","handlingStrategy":"type-guard","validationCode":"bool IsSupportedSetterValue(object v) => v is null || v is DeferredReference || v is DynamicResourceExtension || v is System.Windows.Data.BindingBase || v is not MarkupExtension;","typeGuard":"bool IsAllowedExtension(object v) => v is not MarkupExtension || v is DynamicResourceExtension || v is System.Windows.Data.BindingBase;","tryCatchPattern":"try { style.Seal(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"markup extension\")) { /* replace value */ }","preventionTips":["Only assign DynamicResourceExtension or BindingBase as extension values in code","Resolve custom markup extensions to concrete values before assigning to Setter.Value"],"tags":["wpf","style","markup-extension","setter"],"backgroundTag":"unsupported-operation","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"}