dotnet/wpf · error · InvalidOperationException
SR.Animation_Invalid_DefaultValue
Error message
SR.Animation_Invalid_DefaultValue
What it means
RectAnimation.GetCurrentValueCore throws this InvalidOperationException when the default origin value supplied by the animation system is not a valid animation value for type Rect (checked via AnimatedTypeHelpers.IsValidAnimationValueRect). WPF requires origin/destination fallback values to be valid, finite Rect values; an invalid (e.g. empty or non-animatable) value cannot seed the interpolation. The message names the offending property ('origin') and its value.
Solutions
- Initialize the animated property to a valid, non-empty Rect (e.g. new Rect(0,0,100,100)) before the animation runs
- Provide explicit From/To values on the RectAnimation so default origin/destination values are not needed
- Wrap the animation start in try/catch for InvalidOperationException and fall back to a valid base value
Example fix
// before rectAnimation.From = null; // relies on base value which is Rect.Empty // after rectAnimation.From = new Rect(0, 0, 100, 100); // valid origin, no default needed
Defensive patterns
Strategy: validation
Validate before calling
if (!rect.IsValid || rect == Rect.Empty) { /* fix or set a valid base value before animating */ } Type guard
bool IsValidAnimationOrigin(Rect r) => r != Rect.Empty && r.Width >= 0 && r.Height >= 0;
Try / catch
try { target.BeginAnimation(RectProperty, anim); } catch (InvalidOperationException ex) when (ex.Message.Contains("origin")) { anim.From = new Rect(0,0,1,1); target.BeginAnimation(RectProperty, anim); } Prevention
- Always initialize Rect-typed properties to a non-empty Rect before animating
- Prefer explicit From/To on animations over relying on base values
- Check Rect.IsEmpty before BeginAnimation
When it happens
Trigger: Calling GetCurrentValueCore (directly or via the animation clock) with validateOrigin=true and a defaultOriginValue that fails AnimatedTypeHelpers.IsValidAnimationValueRect — e.g. Rect.Empty or an uninitialized Rect used as the base value of the animated property.
Common situations: Animating a Rect-typed dependency property whose current value is Rect.Empty (e.g. RectangleGeometry.Rect never initialized), or hand-rolled animation code passing an empty/default Rect as the origin.
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.Animation_Invalid_DefaultValue
- SR.Animation_Invalid_DefaultValue
- SR.Animation_Invalid_DefaultValue
- SR.Animation_Invalid_DefaultValue
- SR.Animation_Invalid_DefaultValue
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d0e74b103aa06a0d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/RectAnimation.cs:313
if (IsAdditive)
{
foundation = defaultOriginValue;
validateOrigin = true;
}
break;
default:
Debug.Fail("Unknown animation type.");
break;
}
if (validateOrigin
&& !AnimatedTypeHelpers.IsValidAnimationValueRect(defaultOriginValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"origin",
defaultOriginValue.ToString(CultureInfo.InvariantCulture)));
}
if (validateDestination
&& !AnimatedTypeHelpers.IsValidAnimationValueRect(defaultDestinationValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"destination",
defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));
}
View on GitHub (pinned to 81131a70a4)