{"record":{"id":"a884538f005a6780","repo":"dotnet/wpf","slug":"sr-animation-animationtimelinetypemismatch-ianimatablehelper","errorCode":null,"errorMessage":"SR.Animation_AnimationTimelineTypeMismatch","messagePattern":"SR\\.Animation_AnimationTimelineTypeMismatch","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/IAnimatableHelper.cs","lineNumber":84,"sourceCode":"                    /// Determines how the new AnimationClock will transition from or\n                    /// affect any current animations on the property.\n                    /// </param>\n                    public void ApplyAnimationClock(\n                        DependencyProperty dp,\n                        AnimationClock clock,\n                        HandoffBehavior handoffBehavior)\n                    {\n                        ArgumentNullException.ThrowIfNull(dp);\n\n                        if (!AnimationStorage.IsPropertyAnimatable(this, dp))\n                        {\n                            throw new ArgumentException(SR.Format(SR.Animation_DependencyPropertyIsNotAnimatable, dp.Name, this.GetType()), nameof(dp));\n                        }\n\n                        if (clock != null\n                            && !AnimationStorage.IsAnimationValid(dp, clock.Timeline))\n                        {\n                            throw new ArgumentException(SR.Format(SR.Animation_AnimationTimelineTypeMismatch, clock.Timeline.GetType(), dp.Name, dp.PropertyType), nameof(clock));\n                        }\n\n                        if (!HandoffBehaviorEnum.IsDefined(handoffBehavior))\n                        {\n                            throw new ArgumentException(SR.Animation_UnrecognizedHandoffBehavior);\n                        }\n\n                        if (IsSealed)\n                        {\n                            throw new InvalidOperationException(SR.Format(SR.IAnimatable_CantAnimateSealedDO, dp, this.GetType()));\n                        }\n                        \n                        AnimationStorage.ApplyAnimationClock(this, dp, clock, handoffBehavior);\n                    }\n\n                    /// <summary>\n                    /// Starts an animation for a DependencyProperty. The animation will\n                    /// begin when the next frame is rendered.","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/IAnimatableHelper.cs#L66-L102","documentation":"Thrown by IAnimatable.ApplyAnimationClock when the clock's Timeline is not a valid animation for the target property — AnimationStorage.IsAnimationValid fails because the AnimationTimeline's output type does not match the DependencyProperty's type.","triggerScenarios":"Calling ApplyAnimationClock(dp, clock, handoffBehavior) where clock.Timeline's typed value (e.g. DoubleAnimation producing double) does not match dp.PropertyType (e.g. Color property).","commonSituations":"Using a DoubleAnimation clock on a Color property like SolidColorBrush.Color; passing a clock created for another property type; reusing a clock across differently-typed properties.","solutions":["Use an AnimationTimeline whose target value type matches dp.PropertyType (e.g. ColorAnimation for Color properties).","Check clock.Timeline.GetType() and dp.PropertyType at the call site to confirm compatibility.","Create a new clock for the property instead of reusing one from a differently-typed animation."],"exampleFix":"// before\nbrush.ApplyAnimationClock(SolidColorBrush.ColorProperty, doubleAnimClock);\n// after\nbrush.ApplyAnimationClock(SolidColorBrush.ColorProperty, new ColorAnimation(Colors.Red, TimeSpan.FromSeconds(1)).CreateClock());","handlingStrategy":"validation","validationCode":"if (clock != null && !dp.PropertyType.IsInstanceOfType(((AnimationTimeline)clock.Timeline).GetCurrentValue(default(object), default(object)))) throw new InvalidOperationException(\"Timeline type mismatch\");","typeGuard":"static bool TimelineMatches(AnimationClock clock, DependencyProperty dp) => clock?.Timeline is AnimationTimeline tl && dp.PropertyType.IsAssignableFrom(tl.TargetPropertyType);","tryCatchPattern":"try { target.ApplyAnimationClock(dp, clock, handoff); } catch (ArgumentException ex) when (ex.ParamName == nameof(clock)) { log.Warn($\"Clock timeline {clock.Timeline.GetType()} incompatible with {dp.PropertyType}\"); }","preventionTips":["Match animation class to property type: Double->DoubleAnimation, Color->ColorAnimation, Point->PointAnimation.","Use Storyboards in XAML where the compiler/linter checks target property compatibility.","Don't reuse clocks across properties of different types."],"tags":["wpf","animation","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}