dotnet/wpf · error · InvalidOperationException
SR.Animation_Invalid_DefaultValue
Error message
SR.Animation_Invalid_DefaultValue (destination: {0}, value: {2}) What it means
Int16Animation.GetCurrentValueCore throws this InvalidOperationException when the destination (to) value is not a valid animation value for Int16 (AnimatedTypeHelpers.IsValidAnimationValueInt16 fails). Animations need a valid numeric destination to interpolate toward. The message names parameter 'destination' and the invalid value.
Solutions
- Validate the destination value fits Int16 before animating
- Clamp the bound value to short.MinValue/short.MaxValue
- Fall back to a known-good destination value on failure
Example fix
// before var anim = new Int16Animation(from, (short)userValue, duration); // userValue may exceed range // after short to = (short)Math.Clamp(userValue, short.MinValue, short.MaxValue); var anim = new Int16Animation(from, to, duration);
Defensive patterns
Strategy: validation
Validate before calling
if (to < short.MinValue || to > short.MaxValue) throw new ArgumentOutOfRangeException(nameof(to));
Type guard
static bool IsValidShortValue(int v) => v >= short.MinValue && v <= short.MaxValue;
Try / catch
try { animation.Begin(); } catch (InvalidOperationException ex) when (ex.Message.Contains("destination")) { /* clamp and retry with valid destination */ } Prevention
- Clamp animation destinations with Math.Clamp to short.MinValue/short.MaxValue
- Validate user/data inputs that feed To/By values before animating
- Keep animation endpoint types aligned with the animated property's type
When it happens
Trigger: GetCurrentValueCore invoked with defaultDestinationValue failing IsValidAnimationValueInt16 while validateDestination is true — invalid default destination value supplied to Int16Animation.
Common situations: Data-bound To values producing out-of-range values; animation targets whose property value overflows Int16; malformed default values from generated/custom animation plumbing.
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/8c1d04007acc7073.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Int16Animation.cs:324
break;
}
if (validateOrigin
&& !AnimatedTypeHelpers.IsValidAnimationValueInt16(defaultOriginValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"origin",
defaultOriginValue.ToString(CultureInfo.InvariantCulture)));
}
if (validateDestination
&& !AnimatedTypeHelpers.IsValidAnimationValueInt16(defaultDestinationValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"destination",
defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));
}
if (IsCumulative)
{
double currentRepeat = (double)(animationClock.CurrentIteration - 1);
if (currentRepeat > 0.0)
{
Int16 accumulator = AnimatedTypeHelpers.SubtractInt16(to, from);
accumulated = AnimatedTypeHelpers.ScaleInt16(accumulator, currentRepeat);
}View on GitHub (pinned to 81131a70a4)