dotnet/wpf · error · InvalidOperationException
SR.Animation_Invalid_DefaultValue
Error message
SR.Animation_Invalid_DefaultValue
What it means
Generated animation classes (from AnimationTemplate) validate the default origin value via AnimatedTypeHelpers.IsValidAnimationValue<T> when Go() is called with validateOrigin. If the caller-supplied defaultOriginValue is not a valid animation value for the animated type (e.g. NaN or Infinity for a double), Go() throws InvalidOperationException with SR.Animation_Invalid_DefaultValue, naming the animation type, 'origin', and the offending value.
Solutions
- Validate the origin value before calling Go(): reject double.NaN/Infinity (use double.IsFinite).
- Let the animation compute the origin itself (pass the overload without a default origin value).
- Trace where the origin value is computed and fix the NaN-producing calculation.
- Clamp/sanitize data-bound values via a value converter.
Example fix
// before
anim.Go(null, new object[] { double.NaN, 100.0 }); // invalid origin
// after
if (double.IsFinite(origin))
anim.Go(null, new object[] { origin, 100.0 }); Defensive patterns
Strategy: validation
Validate before calling
if (!double.IsFinite(origin))
origin = 0.0; // or skip the animation
anim.Go(null, new object[] { origin, destination }); Type guard
bool IsValidAnimationOrigin(double v) => double.IsFinite(v);
Try / catch
try { anim.Go(null, new object[] { origin, dest }); }
catch (InvalidOperationException ex) when (ex.Message.Contains("origin"))
{ log.Warn("Invalid animation origin", ex); } Prevention
- Sanitize computed values (NaN/Infinity) before using them as animation origins
- Prefer the Go overload that derives the origin from the current property value
- Use value converters on data-bound animation values to coerce invalid values
When it happens
Trigger: Calling animation.Go(new DoubleAnimation(...), defaultOriginValue: double.NaN/PositiveInfinity, ...) or the generated Go(origin, destination) overload with an invalid origin while validateOrigin is true; data-bound origin values that resolved to NaN.
Common situations: Binding animation origins to computed geometry results (e.g. NaN from a divide by zero in layout math); passing unset (NaN) struct fields as origin values.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 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/2b49e9e0e5c9413b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationTemplate.cs:421
if (IsAdditive)
{
foundation = defaultOriginValue;
validateOrigin = true;
}
break;
default:
Debug.Fail("Unknown animation type.");
break;
}
if (validateOrigin
&& !AnimatedTypeHelpers.IsValidAnimationValue[[instance.TypeName]](defaultOriginValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"origin",
defaultOriginValue.ToString(CultureInfo.InvariantCulture)));
}
if (validateDestination
&& !AnimatedTypeHelpers.IsValidAnimationValue[[instance.TypeName]](defaultDestinationValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"destination",
defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));
}
View on GitHub (pinned to 81131a70a4)