dotnet/wpf · error · ArgumentException

SR.StyleValueOfExpressionNotSupported

Error message

SR.StyleValueOfExpressionNotSupported

What it means

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.

Solutions

  1. Assign a BindingBase (e.g. new Binding(...)) or DynamicResourceExtension instead of the raw Expression.
  2. If copying an existing value, read its source configuration and rebuild a Binding, not the Expression instance.
  3. For dynamic values outside binding/resource support, set the value directly on elements rather than through a Setter.

Example fix

// before
setter.Value = element.GetBindingExpression(Control.BackgroundProperty).ParentBindingBase; // or raw expression
// after
setter.Value = new Binding("MyPath") { Source = myViewModel };
Defensive patterns

Strategy: type-guard

Validate before calling

void SafeSetValue(Setter s, object v) { if (v is Expression) throw new ArgumentException("Use BindingBase instead"); s.Value = v; }

Type guard

bool IsNotExpression(object v) => v is not Expression;

Try / catch

try { setter.Value = candidate; }
catch (ArgumentException ex) when (ex.Message.Contains("Expression")) { /* rebuild as Binding */ }

Prevention

When it happens

Trigger: 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).

Common situations: Advanced property-system code copying values between elements where the source value is an active expression; using reflection to poke binding internals.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/9946392d15e6f6c2. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs:180

                    _value = deferredReference.GetValue(BaseValueSourceInternal.Unknown);
                }

                return _value;
            }

            set
            {
                if( value == DependencyProperty.UnsetValue )
                {
                    throw new ArgumentException(SR.SetterValueCannotBeUnset);
                }

                CheckSealed();

                // No Expression support
                if( value is Expression )
                {
                    throw new ArgumentException(SR.StyleValueOfExpressionNotSupported);
                }


                _value = value;
            }
        }

        /// <summary>
        ///     Internal property used so that we obtain the value as
        ///     is without having to inflate the DeferredReference.
        /// </summary>
        internal object ValueInternal
        {
            get { return _value; }
        }

        /// <summary>
        ///     When the set is directed at a child node, this string

View on GitHub (pinned to 81131a70a4)