dotnet/wpf · error · InvalidOperationException
Animation_Invalid_DefaultValue
Animation_Invalid_DefaultValue
Error message
SR.Animation_Invalid_DefaultValue (Animation_Invalid_DefaultValue)
What it means
ByteAnimation.GetCurrentValueCore throws InvalidOperationException when the animation must supply a default origin value (validateOrigin is true and defaultOriginValue was not provided) but that value is not a valid animation value for Byte (per AnimatedTypeHelpers.IsValidAnimationValueByte). WPF refuses to guess an origin for the animated Byte because no valid starting value exists.
Solutions
- Set the From property on the ByteAnimation so an explicit origin exists
- Pass a valid byte defaultOriginValue when calling GetCurrentValueCore
- Ensure the target property has a valid base value before the animation runs
Example fix
// before
var anim = new ByteAnimation { To = 100 };
animation.BeginAnimation(byteProperty, anim, null); // no origin value
// after
var anim = new ByteAnimation { From = 0, To = 100 }; Defensive patterns
Strategy: validation
Validate before calling
if (!anim.From.HasValue && (defaultOriginValue == null || !IsValidByte(defaultOriginValue)))
anim.From = 0; // supply explicit origin before evaluating Type guard
static bool HasValidOrigin(ByteAnimation a) => a.From.HasValue;
Try / catch
try { value = anim.GetCurrentValue(baseValue, null, clock, defaultClock); }
catch (InvalidOperationException) { /* missing/invalid origin: set From or base value */ } Prevention
- Always set From on From/To/By animations, or ensure the target property has a base value
- Do not call GetCurrentValueCore directly with null default values unless another source exists
- Initialize animated byte properties before starting the animation
When it happens
Trigger: Calling GetCurrentValue/GetCurrentValueCore with defaultOriginValue==null (or an invalid default) while the animation has no From value set and no prior/current value to use as origin.
Common situations: Animating a byte property where neither From nor a base value is available — e.g. animation targeting a property that has never been set, or manually invoking the animation API without origin/destination values.
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_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a0e30776b96bfc1e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/ByteAnimation.cs:313
if (IsAdditive)
{
foundation = defaultOriginValue;
validateOrigin = true;
}
break;
default:
Debug.Fail("Unknown animation type.");
break;
}
if (validateOrigin
&& !AnimatedTypeHelpers.IsValidAnimationValueByte(defaultOriginValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"origin",
defaultOriginValue.ToString(CultureInfo.InvariantCulture)));
}
if (validateDestination
&& !AnimatedTypeHelpers.IsValidAnimationValueByte(defaultDestinationValue))
{
throw new InvalidOperationException(
SR.Format(
SR.Animation_Invalid_DefaultValue,
this.GetType(),
"destination",
defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));
}
View on GitHub (pinned to 81131a70a4)