{"record":{"id":"9946392d15e6f6c2","repo":"dotnet/wpf","slug":"sr-stylevalueofexpressionnotsupported","errorCode":null,"errorMessage":"SR.StyleValueOfExpressionNotSupported","messagePattern":"SR\\.StyleValueOfExpressionNotSupported","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs","lineNumber":180,"sourceCode":"                    _value = deferredReference.GetValue(BaseValueSourceInternal.Unknown);\n                }\n\n                return _value;\n            }\n\n            set\n            {\n                if( value == DependencyProperty.UnsetValue )\n                {\n                    throw new ArgumentException(SR.SetterValueCannotBeUnset);\n                }\n\n                CheckSealed();\n\n                // No Expression support\n                if( value is Expression )\n                {\n                    throw new ArgumentException(SR.StyleValueOfExpressionNotSupported);\n                }\n\n\n                _value = value;\n            }\n        }\n\n        /// <summary>\n        ///     Internal property used so that we obtain the value as\n        ///     is without having to inflate the DeferredReference.\n        /// </summary>\n        internal object ValueInternal\n        {\n            get { return _value; }\n        }\n\n        /// <summary>\n        ///     When the set is directed at a child node, this string","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs#L162-L198","documentation":"Setter.Value does not accept Expression objects (the internal base for bindings/expressions at the core property system level). Assigning one throws ArgumentException; styles only support the public Binding/DynamicResource surface, not raw Expressions.","triggerScenarios":"Code like `setter.Value = someExpression;` where an Expression was obtained from another property system API (e.g. GetExpressionBase, internal expression APIs, or a value read back from an element).","commonSituations":"Advanced property-system code copying values between elements where the source value is an active expression; using reflection to poke binding internals.","solutions":["Assign a BindingBase (e.g. new Binding(...)) or DynamicResourceExtension instead of the raw Expression.","If copying an existing value, read its source configuration and rebuild a Binding, not the Expression instance.","For dynamic values outside binding/resource support, set the value directly on elements rather than through a Setter."],"exampleFix":"// before\nsetter.Value = element.GetBindingExpression(Control.BackgroundProperty).ParentBindingBase; // or raw expression\n// after\nsetter.Value = new Binding(\"MyPath\") { Source = myViewModel };","handlingStrategy":"type-guard","validationCode":"void SafeSetValue(Setter s, object v) { if (v is Expression) throw new ArgumentException(\"Use BindingBase instead\"); s.Value = v; }","typeGuard":"bool IsNotExpression(object v) => v is not Expression;","tryCatchPattern":"try { setter.Value = candidate; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Expression\")) { /* rebuild as Binding */ }","preventionTips":["Never copy Expression instances between property systems; rebuild Bindings from configuration","Use public Binding/DynamicResourceExtension APIs rather than core Expression types"],"tags":["wpf","setter","expression","binding"],"backgroundTag":"unsupported-operation","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"}