{"record":{"id":"b6987ae775cb6d8a","repo":"dotnet/wpf","slug":"animation-calculatedvalueisinvalidforproperty","errorCode":"Animation_CalculatedValueIsInvalidForProperty","errorMessage":"SR.Animation_CalculatedValueIsInvalidForProperty (Animation_CalculatedValueIsInvalidForProperty)","messagePattern":"SR\\.Animation_CalculatedValueIsInvalidForProperty \\(Animation_CalculatedValueIsInvalidForProperty\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/AnimationStorage.cs","lineNumber":336,"sourceCode":"            }\n\n            object value = entry.GetFlattenedEntry(RequestFlags.FullyResolved).Value;\n            if (entry.IsDeferredReference)\n            {\n                DeferredReference dr = (DeferredReference)value;\n                value = dr.GetValue(entry.BaseValueSourceInternal);\n\n                // Set the baseValue back into the entry\n                entry.SetAnimationBaseValue(value);\n            }\n\n            object animatedValue = GetCurrentPropertyValue(this, d, _dependencyProperty, metadata, value);\n\n            if (!_dependencyProperty.IsValidValueInternal(animatedValue))\n            {\n                // If the animation(s) applied to the property have calculated an\n                // invalid value for the property then raise an exception.\n                throw new InvalidOperationException(\n                    SR.Format(\n                        SR.Animation_CalculatedValueIsInvalidForProperty,\n                        _dependencyProperty.Name,\n                        null));\n            }\n            \n            entry.SetAnimatedValue(animatedValue, value);\n        }\n\n        #endregion\n\n        #region Private\n\n        private void OnCurrentTimeInvalidated(object sender, EventArgs args)\n        {\n            object target = _dependencyObject.Target;\n\n            if (target == null)","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/AnimationStorage.cs#L318-L354","documentation":"During property evaluation in AnimationStorage, the value calculated by the animation(s) applied to a dependency property failed IsValidValueInternal validation. WPF throws InvalidOperationException because an animated value the property type rejects indicates a broken animation pipeline.","triggerScenarios":"An AnimationClock's GetCurrentValue returns a value whose type/value is invalid for the target dependency property (e.g. animating a Double property toward NaN/Infinity, or a wrong-typed keyframe output).","commonSituations":"Custom AnimationTimeline producing out-of-domain values (NaN, Infinity); type mismatches between keyframes and property type; animations on properties with strict value validation.","solutions":["Fix the custom animation/keyframe so GetCurrentValue always returns a valid typed value for the property","Clamp calculated values (guard against NaN/Infinity) before returning them","Verify the animation type matches the property type (DoubleAnimation for doubles, etc.)"],"exampleFix":"// before\nprotected override double GetCurrentValueCore(...) => baseValue / (target - from); // can yield NaN\n// after\nprotected override double GetCurrentValueCore(...) { var d = target - from; return Math.Abs(d) < double.Epsilon ? to : baseValue / d; }","handlingStrategy":"validation","validationCode":"object v = animationClock.GetCurrentValue(baseValue, defaultDestinationValue);\nbool ok = v is double d && !double.IsNaN(d) && !double.IsInfinity(d);","typeGuard":"static bool IsValidAnimatedValue(object v) => v is not null && !(v is double d && (double.IsNaN(d) || double.IsInfinity(d)));","tryCatchPattern":"try { element.BeginAnimation(prop, anim); } catch (InvalidOperationException ex) { log.Error(ex); }","preventionTips":["Guard custom animations against NaN/Infinity","Keep animation output types aligned with the dependency property type"],"tags":["wpf","animation","dependency-property"],"backgroundTag":"invalid-argument-value","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"}