dotnet/wpf · error · InvalidOperationException

SR.Animation_Invalid_DefaultValue

Error message

SR.Animation_Invalid_DefaultValue (origin: {0}, value: {2})

What it means

DoubleAnimation.GetCurrentValueCore throws InvalidOperationException when origin validation is requested and the default origin value fails AnimatedTypeHelpers.IsValidAnimationValueDouble. WPF will not interpolate from an invalid double (e.g. NaN/unset base value); the message names the animation type, role (origin) and the value.

Solutions

  1. Set an explicit From value on the DoubleAnimation
  2. Ensure the animated property has a concrete, valid double value before BeginAnimation (avoid NaN)
  3. Delay animation start until layout assigns the value (e.g. after Loaded)
  4. Animate a different property or use a layout-safe target

Example fix

// before
var anim = new DoubleAnimation(100, TimeSpan.FromSeconds(1)); // From = default (NaN for Width)
// after
element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); // ensure valid base value
var anim = new DoubleAnimation { From = element.ActualWidth, To = 100, Duration = TimeSpan.FromSeconds(1) };
Defensive patterns

Strategy: validation

Validate before calling

if (double.IsNaN(currentValue) || !AnimatedTypeHelpers.IsValidAnimationValueDouble(currentValue))
    anim.From = 0; // provide a concrete origin

Type guard

static bool IsValidDoubleOrigin(double v) => !double.IsNaN(v) && !double.IsInfinity(v) && AnimatedTypeHelpers.IsValidAnimationValueDouble(v);

Try / catch

try { target.BeginAnimation(depProp, anim); }
catch (InvalidOperationException ex) when (ex.Message.Contains("origin")) { /* set From explicitly and retry */ }

Prevention

When it happens

Trigger: defaultOriginValue invalid (commonly double.NaN or an unset property default) while validateOrigin is true and no explicit From value is set on the DoubleAnimation.

Common situations: Animating Width/Height/Opacity-like double properties before layout has assigned a value (NaN); relying on the current value as origin without From; sentinel double defaults.

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/95232242989705e7. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/DoubleAnimation.cs:313

                    if (IsAdditive)
                    {
                        foundation = defaultOriginValue;
                        validateOrigin = true;
                    }

                    break;

                default:

                    Debug.Fail("Unknown animation type.");

                    break;
            }

            if (validateOrigin 
                && !AnimatedTypeHelpers.IsValidAnimationValueDouble(defaultOriginValue))
            {
                throw new InvalidOperationException(
                    SR.Format(
                        SR.Animation_Invalid_DefaultValue,
                        this.GetType(),
                        "origin",
                        defaultOriginValue.ToString(CultureInfo.InvariantCulture)));
            }

            if (validateDestination 
                && !AnimatedTypeHelpers.IsValidAnimationValueDouble(defaultDestinationValue))
            {
                throw new InvalidOperationException(
                    SR.Format(
                        SR.Animation_Invalid_DefaultValue,
                        this.GetType(),
                        "destination",
                        defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));
            }

View on GitHub (pinned to 81131a70a4)