dotnet/wpf · error · ArgumentException

Animation_AnimationTimelineTypeMismatch

Animation_AnimationTimelineTypeMismatch

Error message

SR.Animation_AnimationTimelineTypeMismatch (Animation_AnimationTimelineTypeMismatch)

What it means

The clock passed to ApplyAnimationClock carries a Timeline whose type does not match the type the target DependencyProperty expects. AnimationStorage.IsAnimationValid validates that clock.Timeline is an AnimationTimeline compatible with dp.PropertyType; if not, this ArgumentException is thrown. WPF animations are strongly typed: e.g. a DoubleAnimation clock cannot target a Color property.

Solutions

  1. Check the DP's PropertyType and use the matching animation timeline type (DoubleAnimation for doubles, ColorAnimation for Color, etc.).
  2. If using key frames, ensure the key-frame animation's value type matches the property (e.g. ColorKeyFrameCollection for Color properties).
  3. Guard with a runtime check before applying: verify clock.Timeline.TargetPropertyType == dp.PropertyType.

Example fix

// before
rect.ApplyAnimationClock(Rectangle.FillProperty, new DoubleAnimation(0, 1, dur).CreateClock()); // wrong type
// after
rect.ApplyAnimationClock(Rectangle.FillProperty, new ColorAnimation(Colors.Red, Colors.Blue, dur).CreateClock());
Defensive patterns

Strategy: validation

Validate before calling

if (clock != null && clock.Timeline.TargetPropertyType != dp.PropertyType)
    throw new ArgumentException("Timeline type mismatch with property type");

Type guard

static bool ClockMatches(DependencyProperty dp, AnimationClock clock) =>
    clock == null || (clock.Timeline as AnimationTimeline)?.TargetPropertyType == dp.PropertyType;

Try / catch

try { target.ApplyAnimationClock(dp, clock); }
catch (ArgumentException ex) when (ex.ParamName == nameof(clock)) { /* swap to correct animation type */ }

Prevention

When it happens

Trigger: Calling ApplyAnimationClock(dp, clock) where clock is non-null and clock.Timeline's typed value type differs from dp.PropertyType (e.g. applying a DoubleAnimationUsingKeyFrames clock to a SolidColorBrush.ColorProperty).

Common situations: Mixing animation types when scripting many properties; copying a clock factory from one property to another; refactors that change a property's type (Double to Color) without updating animation code.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/882e6445a9aef286. Report an issue: GitHub.

Appendix: source

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

        /// Determines how the new AnimationClock will transition from or
        /// affect any current animations on the property.
        /// </param>
        public void ApplyAnimationClock(
            DependencyProperty dp,
            AnimationClock clock,
            HandoffBehavior handoffBehavior)
        {
            ArgumentNullException.ThrowIfNull(dp);

            if (!AnimationStorage.IsPropertyAnimatable(this, dp))
            {
                throw new ArgumentException(SR.Format(SR.Animation_DependencyPropertyIsNotAnimatable, dp.Name, this.GetType()), nameof(dp));
            }

            if (clock != null
                && !AnimationStorage.IsAnimationValid(dp, clock.Timeline))
            {
                throw new ArgumentException(SR.Format(SR.Animation_AnimationTimelineTypeMismatch, clock.Timeline.GetType(), dp.Name, dp.PropertyType), nameof(clock));
            }

            if (!HandoffBehaviorEnum.IsDefined(handoffBehavior))
            {
                throw new ArgumentException(SR.Animation_UnrecognizedHandoffBehavior);
            }

            if (IsSealed)
            {
                throw new InvalidOperationException(SR.Format(SR.IAnimatable_CantAnimateSealedDO, dp, this.GetType()));
            }

            AnimationStorage.ApplyAnimationClock(this, dp, clock, handoffBehavior);
        }

        /// <summary>
        /// Starts an animation for a DependencyProperty. The animation will
        /// begin when the next frame is rendered.

View on GitHub (pinned to 81131a70a4)