dotnet/wpf · error · ArgumentException
SR.InvalidPropertyValue
Error message
SR.InvalidPropertyValue
What it means
The Condition constructor validates that conditionValue is a valid value for conditionProperty by calling DependencyProperty.IsValidValue. If the value's type is wrong or out of range for the dependency property, it throws ArgumentException (InvalidPropertyValue).
Solutions
- Use a value that satisfies conditionProperty.IsValidValue (e.g. proper CLR type, enum cast, valid range)
- Use dp.PropertyType to coerce/convert the value (e.g. TypeConverter or Enum.Parse) before constructing the Condition
- Validate with conditionProperty.IsValidValue(value) before calling the constructor
Example fix
// before new Condition(UIElement.VisibilityProperty, "Visible"); // wrong type // after new Condition(UIElement.VisibilityProperty, Visibility.Visible);
Defensive patterns
Strategy: validation
Validate before calling
if (!conditionProperty.IsValidValue(conditionValue)) throw new ArgumentException($"Value {conditionValue} invalid for {conditionProperty.Name}"); Type guard
bool IsValidConditionValue(DependencyProperty dp, object v) => dp.IsValidValue(v);
Try / catch
try { var c = new Condition(dp, value); } catch (ArgumentException ex) { /* coerce value via dp.PropertyType and retry */ } Prevention
- Coerce values to dp.PropertyType before constructing Conditions
- Use actual enum values, not strings
- Call IsValidValue as a pre-check in helper code
When it happens
Trigger: new Condition(dp, value, ...) where value fails dp.IsValidValue — e.g. passing a string for a double property, or a value outside the property's validation range.
Common situations: Building Trigger/ MultiTrigger conditions in code with loosely-typed values; type mismatches after refactoring a property's CLR type; strings used for enum properties that need actual enum values.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.ConditionValueOfMarkupExtensionNotSupported
- SR.Format(SR.InvalidCtorParameterNoNaN, "value")
- SR.PrintDialogInvalidPageRange
- UriMustBeAbsolute
- " }} " element found. Expected fixed page element ( }} ).
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/39ff77fca24cf27c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs:51
// Call Forwarded
}
/// <summary>
/// Constructor for creating a Condition with the given property
/// and value instead of creating an empty one and setting values later.
/// </summary>
/// <remarks>
/// This constructor does parameter validation, which before doesn't
/// happen until Seal() is called. We can do it here because we get
/// both at the same time.
/// </remarks>
public Condition( DependencyProperty conditionProperty, object conditionValue, string sourceName )
{
ArgumentNullException.ThrowIfNull(conditionProperty);
if (!conditionProperty.IsValidValue(conditionValue))
{
throw new ArgumentException(SR.Format(SR.InvalidPropertyValue, conditionValue, conditionProperty.Name));
}
_property = conditionProperty;
Value = conditionValue;
_sourceName = sourceName;
}
/// <summary>
/// Constructor for creating a Condition with the given binding declaration.
/// and value.
/// </summary>
public Condition( BindingBase binding, object conditionValue )
{
ArgumentNullException.ThrowIfNull(binding);
Binding = binding;
Value = conditionValue;
}View on GitHub (pinned to 81131a70a4)