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
- Check the DP's PropertyType and use the matching animation timeline type (DoubleAnimation for doubles, ColorAnimation for Color, etc.).
- If using key frames, ensure the key-frame animation's value type matches the property (e.g. ColorKeyFrameCollection for Color properties).
- 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
- Pair animation classes with property types explicitly.
- Centralize clock creation in helpers that take the DP and return a matching timeline.
- Re-check animation code whenever a DP's type changes.
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
- SR.Animation_AnimationTimelineTypeMismatch
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
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)