dotnet/wpf · error · InvalidOperationException

SR.Animation_Invalid_DefaultValue

Error message

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

What it means

ColorAnimation.GetCurrentValueCore throws InvalidOperationException (SR.Animation_Invalid_DefaultValue) when validateOrigin is true and the provided defaultOriginValue is not a valid Color animation value (AnimatedTypeHelpers.IsValidAnimationValueColor fails). WPF requires a valid origin Color when the animation has no From value to fall back on. The message identifies the animation type, the "origin" slot, and the offending value.

Solutions

  1. Set the From property (e.g. new ColorAnimation { From = Colors.Red, To = Colors.Blue })
  2. Pass a valid Color defaultOriginValue when calling GetCurrentValueCore
  3. Ensure the animated property has a valid base Color before the animation begins

Example fix

// before
var anim = new ColorAnimation { To = Colors.Blue }; // no origin
// after
var anim = new ColorAnimation { From = Colors.Red, To = Colors.Blue };
Defensive patterns

Strategy: validation

Validate before calling

if (anim.From is null && (defaultOriginValue is null || !IsValidColor(defaultOriginValue)))
    anim.From = Colors.Transparent; // supply explicit origin before evaluating

Type guard

static bool HasValidOrigin(ColorAnimation a) => a.From.HasValue;

Try / catch

try { value = anim.GetCurrentValue(baseValue, null, clock, defaultClock); }
catch (InvalidOperationException) { /* invalid origin: set From or a base Color on the target property */ }

Prevention

When it happens

Trigger: Calling GetCurrentValue/GetCurrentValueCore with a null/invalid defaultOriginValue while the ColorAnimation has no From set and no base value exists to serve as origin.

Common situations: Animating a Brush/Color property that has never been assigned a base color, or manually invoking the animation evaluation API with a null origin value.

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/3c8f29c39d879598. Report an issue: GitHub.

Appendix: source

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

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

                    break;

                default:

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

                    break;
            }

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

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

View on GitHub (pinned to 81131a70a4)