dotnet/wpf · error · ArgumentException

SR.Format(SR.Animation_AnimationTimelineTypeMismatch…

Error message

SR.Format(SR.Animation_AnimationTimelineTypeMismatch, clock.Timeline.GetType(), dp.Name, dp.PropertyType)

What it means

Thrown by ContentElement.ApplyAnimationClock when a non-null clock's Timeline does not validate against the target property (AnimationStorage.IsAnimationValid fails). The clock's AnimationTimeline produces values of a type incompatible with the DependencyProperty's property type, so the library throws ArgumentException naming the timeline type, property name, and expected property type.

Solutions

  1. Use an AnimationTimeline whose target value type matches dp.PropertyType (DoubleAnimation for doubles, ColorAnimation for Color, etc.).
  2. Check the mismatch message: it names the timeline type, the property, and the expected property type — align the clock accordingly.
  3. Verify AnimationStorage.IsAnimationValid(dp, clock.Timeline) before applying the clock.
  4. For non-double types, use matching keyframe/animation classes (e.g. PointAnimation, ThicknessAnimation).

Example fix

// before
var clock = new ColorAnimation(Colors.Red, Duration.Forever).CreateClock();
el.ApplyAnimationClock(TextElement.FontSizeProperty, clock); // FontSize is double
// after
var clock = new DoubleAnimation(12, 24, Duration.Forever).CreateClock();
el.ApplyAnimationClock(TextElement.FontSizeProperty, clock);
Defensive patterns

Strategy: type-guard

Validate before calling

if (clock?.Timeline is AnimationTimeline tl && !AnimationStorage.IsAnimationValid(dp, tl))
    throw new InvalidOperationException($"Clock timeline type {tl.GetType().Name} does not match {dp.PropertyType}");

Type guard

bool ClockMatchesProp<TValue>(DependencyProperty dp, Clock c) => dp.PropertyType == typeof(TValue) && c.Timeline is AnimationTimeline;

Try / catch

try { el.ApplyAnimationClock(dp, clock); }
catch (ArgumentException ex) when (ex.ParamName == nameof(clock)) { log.Error("Timeline/property type mismatch", ex); }

Prevention

When it happens

Trigger: Calling ApplyAnimationClock(dp, clock) where clock.Timeline's output type does not match dp.PropertyType — e.g. a DoubleAnimation clock applied to a Color-typed property.

Common situations: Reusing one AnimationClock across properties of different types (double vs Color vs Thickness); refactoring code that changed a property's type but kept the old animation; constructing clocks from timelines via CreateClock and attaching to the wrong DP.

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/157e59dec45be8a4. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs:77

        /// 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)