{"record":{"id":"882e6445a9aef286","repo":"dotnet/wpf","slug":"animation-animationtimelinetypemismatch","errorCode":"Animation_AnimationTimelineTypeMismatch","errorMessage":"SR.Animation_AnimationTimelineTypeMismatch (Animation_AnimationTimelineTypeMismatch)","messagePattern":"SR\\.Animation_AnimationTimelineTypeMismatch \\(Animation_AnimationTimelineTypeMismatch\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs","lineNumber":76,"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":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Animatable.cs#L58-L94","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nrect.ApplyAnimationClock(Rectangle.FillProperty, new DoubleAnimation(0, 1, dur).CreateClock()); // wrong type\n// after\nrect.ApplyAnimationClock(Rectangle.FillProperty, new ColorAnimation(Colors.Red, Colors.Blue, dur).CreateClock());","handlingStrategy":"validation","validationCode":"if (clock != null && clock.Timeline.TargetPropertyType != dp.PropertyType)\n    throw new ArgumentException(\"Timeline type mismatch with property type\");","typeGuard":"static bool ClockMatches(DependencyProperty dp, AnimationClock clock) =>\n    clock == null || (clock.Timeline as AnimationTimeline)?.TargetPropertyType == dp.PropertyType;","tryCatchPattern":"try { target.ApplyAnimationClock(dp, clock); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(clock)) { /* swap to correct animation type */ }","preventionTips":["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."],"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-21T21:30:21.729Z"}