dotnet/wpf · error · InvalidOperationException

Animation_CalculatedValueIsInvalidForProperty

Animation_CalculatedValueIsInvalidForProperty

Error message

SR.Animation_CalculatedValueIsInvalidForProperty (Animation_CalculatedValueIsInvalidForProperty)

What it means

During property evaluation in AnimationStorage, the value calculated by the animation(s) applied to a dependency property failed IsValidValueInternal validation. WPF throws InvalidOperationException because an animated value the property type rejects indicates a broken animation pipeline.

Solutions

  1. Fix the custom animation/keyframe so GetCurrentValue always returns a valid typed value for the property
  2. Clamp calculated values (guard against NaN/Infinity) before returning them
  3. Verify the animation type matches the property type (DoubleAnimation for doubles, etc.)

Example fix

// before
protected override double GetCurrentValueCore(...) => baseValue / (target - from); // can yield NaN
// after
protected override double GetCurrentValueCore(...) { var d = target - from; return Math.Abs(d) < double.Epsilon ? to : baseValue / d; }
Defensive patterns

Strategy: validation

Validate before calling

object v = animationClock.GetCurrentValue(baseValue, defaultDestinationValue);
bool ok = v is double d && !double.IsNaN(d) && !double.IsInfinity(d);

Type guard

static bool IsValidAnimatedValue(object v) => v is not null && !(v is double d && (double.IsNaN(d) || double.IsInfinity(d)));

Try / catch

try { element.BeginAnimation(prop, anim); } catch (InvalidOperationException ex) { log.Error(ex); }

Prevention

When it happens

Trigger: An AnimationClock's GetCurrentValue returns a value whose type/value is invalid for the target dependency property (e.g. animating a Double property toward NaN/Infinity, or a wrong-typed keyframe output).

Common situations: Custom AnimationTimeline producing out-of-domain values (NaN, Infinity); type mismatches between keyframes and property type; animations on properties with strict value validation.

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


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/AnimationStorage.cs:336

            }

            object value = entry.GetFlattenedEntry(RequestFlags.FullyResolved).Value;
            if (entry.IsDeferredReference)
            {
                DeferredReference dr = (DeferredReference)value;
                value = dr.GetValue(entry.BaseValueSourceInternal);

                // Set the baseValue back into the entry
                entry.SetAnimationBaseValue(value);
            }

            object animatedValue = GetCurrentPropertyValue(this, d, _dependencyProperty, metadata, value);

            if (!_dependencyProperty.IsValidValueInternal(animatedValue))
            {
                // If the animation(s) applied to the property have calculated an
                // invalid value for the property then raise an exception.
                throw new InvalidOperationException(
                    SR.Format(
                        SR.Animation_CalculatedValueIsInvalidForProperty,
                        _dependencyProperty.Name,
                        null));
            }
            
            entry.SetAnimatedValue(animatedValue, value);
        }

        #endregion

        #region Private

        private void OnCurrentTimeInvalidated(object sender, EventArgs args)
        {
            object target = _dependencyObject.Target;

            if (target == null)

View on GitHub (pinned to 81131a70a4)