dotnet/wpf · error · InvalidOperationException

SR.Animation_Invalid_DefaultValue

Error message

SR.Animation_Invalid_DefaultValue

What it means

SingleAnimation.GetCurrentValueCore throws InvalidOperationException (SR.Animation_Invalid_DefaultValue) when the animation is asked to compute a value using a default 'origin' value that is not a valid animation value for Single (NaN, +/-Infinity), and no explicit From value was supplied. WPF validates that any fallback value used as the animation's base value is a finite float.

Solutions

  1. Set an explicit From value on the SingleAnimation so defaultOriginValue is never used (e.g. new DoubleAnimation { From = 0, To = 100 }).
  2. Ensure the property being animated holds a finite value: check double.IsFinite(baseValue) before calling GetCurrentValue or starting the animation.
  3. Fix the upstream data binding/calculation that produced NaN or Infinity (guard divisions, provide FallbackValue in the Binding).
  4. Wrap GetCurrentValue calls in try/catch for InvalidOperationException as a last resort and substitute a finite default.

Example fix

// before
var value = animation.GetCurrentValue(baseValue, targetValue, clock); // baseValue may be NaN
// after
if (!float.IsFinite(baseValue)) baseValue = 0f;
var value = animation.GetCurrentValue(baseValue, targetValue, clock);
Defensive patterns

Strategy: validation

Validate before calling

if (float.IsNaN(defaultOriginValue) || float.IsInfinity(defaultOriginValue))
    defaultOriginValue = 0f; // or throw a friendly app-level error
animation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, clock);

Type guard

static bool IsValidSingle(float v) => !float.IsNaN(v) && !float.IsInfinity(v);

Try / catch

try
{
    value = animation.GetCurrentValue(origin, destination, clock);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("origin"))
{
    value = destination; // finite fallback
}

Prevention

When it happens

Trigger: Calling animation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, animationClock) with defaultOriginValue = float.NaN, float.PositiveInfinity or float.NegativeInfinity while validateOrigin is true (i.e. no From/To specified so defaults are used).

Common situations: Base property or earlier animation produced NaN (e.g. width computed from a divide-by-zero); binding a Double/Single property to an unset or failed data binding that yields NaN; passing Infinity as the base value in custom animation code.

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/321c57496d9367cf. Report an issue: GitHub.

Appendix: source

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

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

                    break;

                default:

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

                    break;
            }

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

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

View on GitHub (pinned to 81131a70a4)