dotnet/wpf · error · InvalidOperationException
SR.Format(SR.InvalidPropertyValue, _value, _property.Name)
Error message
SR.Format(SR.InvalidPropertyValue, _value, _property.Name)
What it means
During Trigger.Seal(), if Property is set, the framework validates that the condition Value is a valid value for that dependency property via IsValidValue. An out-of-domain value (wrong type or outside enum coercion) throws InvalidOperationException with SR.InvalidPropertyValue showing the value and property name.
Solutions
- Set a Value whose type matches the property (e.g. 0.5 for Opacity, proper enum member for enums).
- Use the property's type converter to convert strings first (e.g. TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromString(s)) and verify IsValidValue yourself.
- Validate before sealing: if (!prop.IsValidValue(value)) fix or reject the value.
Example fix
// before trigger.Property = UIElement.OpacityProperty; trigger.Value = "high"; // throws on Seal // after trigger.Property = UIElement.OpacityProperty; trigger.Value = 0.5;
Defensive patterns
Strategy: validation
Validate before calling
if (trigger.Property != null && !trigger.Property.IsValidValue(value))
throw new InvalidOperationException($"{value} is not valid for {trigger.Property.Name}"); Type guard
static bool IsValidFor(Trigger t) => t.Property == null || t.Property.IsValidValue(t.Value);
Try / catch
try { style.Seal(); /* or trigger seal via style use */ }
catch (InvalidOperationException ex) { log.Error($"Trigger condition invalid: {ex.Message}"); } Prevention
- Match value type to the dependency property's type exactly
- Convert strings with the property's TypeConverter before assigning
- Call DependencyProperty.IsValidValue as a pre-flight check
When it happens
Trigger: trigger.Property = UIElement.OpacityProperty; trigger.Value = "high"; then Seal()/style application — the string is not a valid double for Opacity. Also enum values of the wrong enum type.
Common situations: Assigning a value of the wrong type for the property (string where double/enum expected); copy-pasting values across properties; values typed from parsed config strings.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- SR.Format(SR.CannotChangeAfterSealed, "Trigger")
- SR.Format(SR.DefaultValueInvalid, propertyName)
- SR.Format(SR.InvalidPropertyValue, value…
- SR.Format(SR.ReadOnlyDesignerCoersionNotAllowed, Name)
- SR.Format(SR.ReadOnlyOverrideNotAllowed, Name)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9df0164580fb2c29.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs:199
throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(Setter)), nameof(o));
}
return setter;
}
internal sealed override void Seal()
{
if (IsSealed)
{
return;
}
if (_property != null)
{
// Ensure valid condition
if (!_property.IsValidValue(_value))
{
throw new InvalidOperationException(SR.Format(SR.InvalidPropertyValue, _value, _property.Name ));
}
}
// Freeze the condition for the trigger
StyleHelper.SealIfSealable(_value);
// Process the _setters collection: Copy values into PropertyValueList and seal the Setter objects.
ProcessSettersCollection(_setters);
// Build conditions array from collection
TriggerConditions = new TriggerCondition[] {
new TriggerCondition(
_property,
LogicalOp.Equals,
_value,
_sourceName ?? StyleHelper.SelfName) };
// Set Condition for all property triggersView on GitHub (pinned to 81131a70a4)