{"record":{"id":"3badc6a2940cfb18","repo":"dotnet/wpf","slug":"sr-format-sr-animation-animationtimelinetypemismatch","errorCode":null,"errorMessage":"SR.Format(SR.Animation_AnimationTimelineTypeMismatch, animation.GetType(), dp.Name, dp.PropertyType)","messagePattern":"SR\\.Format\\(SR\\.Animation_AnimationTimelineTypeMismatch, animation\\.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":142,"sourceCode":"        /// and the property value will revert back to its base value.</para>\n        /// </param>\n        /// <param name=\"handoffBehavior\">\n        /// Specifies how the new animation should interact with any current\n        /// animations already affecting the property value.\n        /// </param>\n        public void BeginAnimation(DependencyProperty dp, AnimationTimeline animation, 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 (animation != null\n                && !AnimationStorage.IsAnimationValid(dp, animation))\n            {\n                throw new ArgumentException(SR.Format(SR.Animation_AnimationTimelineTypeMismatch, animation.GetType(), dp.Name, dp.PropertyType), nameof(animation));\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.BeginAnimation(this, dp, animation, handoffBehavior);\n        }\n\n        /// <summary>\n        /// Returns true if any properties on this DependencyObject have a\n        /// persistent animation or the object has one or more clocks associated","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Generated/ContentElement.cs#L124-L160","documentation":"Thrown by ContentElement.BeginAnimation when a non-null animation's type is invalid for the target property (AnimationStorage.IsAnimationValid(dp, animation) fails). The AnimationTimeline's value type does not match dp.PropertyType, producing an ArgumentException that names the animation type, property, and expected type.","triggerScenarios":"Calling BeginAnimation(dp, animation) with an AnimationTimeline whose output type mismatches dp.PropertyType — e.g. ColorAnimation applied to a double-typed property.","commonSituations":"Reusing a single animation instance for properties of differing types; type changes during refactoring leaving stale animation classes; generic helper methods constructing the wrong animation type.","solutions":["Use the animation class matching dp.PropertyType (DoubleAnimation, ColorAnimation, PointAnimation, ThicknessAnimation, etc.).","Read the exception message: it lists animation type, dp.Name, and dp.PropertyType — swap the animation accordingly.","Validate with AnimationStorage.IsAnimationValid(dp, animation) before calling BeginAnimation.","In generic helpers, resolve the animation type from dp.PropertyType at runtime."],"exampleFix":"// before\ncontentEl.BeginAnimation(TextElement.FontSizeProperty, new ColorAnimation(Colors.Red, TimeSpan.FromSeconds(1)));\n// after\ncontentEl.BeginAnimation(TextElement.FontSizeProperty, new DoubleAnimation(12, 24, TimeSpan.FromSeconds(1)));","handlingStrategy":"type-guard","validationCode":"if (animation != null && !AnimationStorage.IsAnimationValid(dp, animation))\n    throw new InvalidOperationException($\"{animation.GetType().Name} cannot animate {dp.Name} ({dp.PropertyType})\");","typeGuard":"bool AnimationMatches<TValue>(DependencyProperty dp, AnimationTimeline a) where TValue : AnimationTimeline => a is TValue && dp.PropertyType == typeof(TValue);","tryCatchPattern":"try { el.BeginAnimation(dp, animation); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(animation)) { log.Error(\"Animation type mismatch\", ex); }","preventionTips":["Pick the animation class matching dp.PropertyType exactly.","Check the exception message triplet (animation type, dp.Name, dp.PropertyType) when debugging.","Avoid reusing one AnimationTimeline instance across differently-typed properties.","Type-check animations in generic animation helpers before calling BeginAnimation."],"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"}