{"record":{"id":"157e59dec45be8a4","repo":"dotnet/wpf","slug":"sr-format-sr-animation-animationtimelinetypemismatch-clock","errorCode":null,"errorMessage":"SR.Format(SR.Animation_AnimationTimelineTypeMismatch, clock.Timeline.GetType(), dp.Name, dp.PropertyType)","messagePattern":"SR\\.Format\\(SR\\.Animation_AnimationTimelineTypeMismatch, clock\\.Timeline\\.GetType\\(\\), dp\\.Name, dp\\.PropertyType\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs","lineNumber":77,"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":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs#L59-L95","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use an AnimationTimeline whose target value type matches dp.PropertyType (DoubleAnimation for doubles, ColorAnimation for Color, etc.).","Check the mismatch message: it names the timeline type, the property, and the expected property type — align the clock accordingly.","Verify AnimationStorage.IsAnimationValid(dp, clock.Timeline) before applying the clock.","For non-double types, use matching keyframe/animation classes (e.g. PointAnimation, ThicknessAnimation)."],"exampleFix":"// before\nvar clock = new ColorAnimation(Colors.Red, Duration.Forever).CreateClock();\nel.ApplyAnimationClock(TextElement.FontSizeProperty, clock); // FontSize is double\n// after\nvar clock = new DoubleAnimation(12, 24, Duration.Forever).CreateClock();\nel.ApplyAnimationClock(TextElement.FontSizeProperty, clock);","handlingStrategy":"type-guard","validationCode":"if (clock?.Timeline is AnimationTimeline tl && !AnimationStorage.IsAnimationValid(dp, tl))\n    throw new InvalidOperationException($\"Clock timeline type {tl.GetType().Name} does not match {dp.PropertyType}\");","typeGuard":"bool ClockMatchesProp<TValue>(DependencyProperty dp, Clock c) => dp.PropertyType == typeof(TValue) && c.Timeline is AnimationTimeline;","tryCatchPattern":"try { el.ApplyAnimationClock(dp, clock); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(clock)) { log.Error(\"Timeline/property type mismatch\", ex); }","preventionTips":["Match animation class to property type: DoubleAnimation for double, ColorAnimation for Color.","Keep one clock per property type; do not share clocks across differently-typed DPs.","Consult dp.PropertyType before constructing the animation/timeline.","Add compile-time generic helpers that enforce timeline/property type pairing."],"tags":["wpf","animation","type-mismatch","argument-exception"],"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"}