{"record":{"id":"321c57496d9367cf","repo":"dotnet/wpf","slug":"sr-animation-invalid-defaultvalue-singleanimation","errorCode":null,"errorMessage":"SR.Animation_Invalid_DefaultValue","messagePattern":"SR\\.Animation_Invalid_DefaultValue","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/SingleAnimation.cs","lineNumber":313,"sourceCode":"                    if (IsAdditive)\n                    {\n                        foundation = defaultOriginValue;\n                        validateOrigin = true;\n                    }\n\n                    break;\n\n                default:\n\n                    Debug.Fail(\"Unknown animation type.\");\n\n                    break;\n            }\n\n            if (validateOrigin \n                && !AnimatedTypeHelpers.IsValidAnimationValueSingle(defaultOriginValue))\n            {\n                throw new InvalidOperationException(\n                    SR.Format(\n                        SR.Animation_Invalid_DefaultValue,\n                        this.GetType(),\n                        \"origin\",\n                        defaultOriginValue.ToString(CultureInfo.InvariantCulture)));\n            }\n\n            if (validateDestination \n                && !AnimatedTypeHelpers.IsValidAnimationValueSingle(defaultDestinationValue))\n            {\n                throw new InvalidOperationException(\n                    SR.Format(\n                        SR.Animation_Invalid_DefaultValue,\n                        this.GetType(),\n                        \"destination\",\n                        defaultDestinationValue.ToString(CultureInfo.InvariantCulture)));\n            }\n","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/SingleAnimation.cs#L295-L331","documentation":"SingleAnimation.GetCurrentValueCore throws InvalidOperationException (SR.Animation_Invalid_DefaultValue) when the animation is asked to compute a value using a default 'origin' value that is not a valid animation value for Single (NaN, +/-Infinity), and no explicit From value was supplied. WPF validates that any fallback value used as the animation's base value is a finite float.","triggerScenarios":"Calling animation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, animationClock) with defaultOriginValue = float.NaN, float.PositiveInfinity or float.NegativeInfinity while validateOrigin is true (i.e. no From/To specified so defaults are used).","commonSituations":"Base property or earlier animation produced NaN (e.g. width computed from a divide-by-zero); binding a Double/Single property to an unset or failed data binding that yields NaN; passing Infinity as the base value in custom animation code.","solutions":["Set an explicit From value on the SingleAnimation so defaultOriginValue is never used (e.g. new DoubleAnimation { From = 0, To = 100 }).","Ensure the property being animated holds a finite value: check double.IsFinite(baseValue) before calling GetCurrentValue or starting the animation.","Fix the upstream data binding/calculation that produced NaN or Infinity (guard divisions, provide FallbackValue in the Binding).","Wrap GetCurrentValue calls in try/catch for InvalidOperationException as a last resort and substitute a finite default."],"exampleFix":"// before\nvar value = animation.GetCurrentValue(baseValue, targetValue, clock); // baseValue may be NaN\n// after\nif (!float.IsFinite(baseValue)) baseValue = 0f;\nvar value = animation.GetCurrentValue(baseValue, targetValue, clock);","handlingStrategy":"validation","validationCode":"if (float.IsNaN(defaultOriginValue) || float.IsInfinity(defaultOriginValue))\n    defaultOriginValue = 0f; // or throw a friendly app-level error\nanimation.GetCurrentValue(defaultOriginValue, defaultDestinationValue, clock);","typeGuard":"static bool IsValidSingle(float v) => !float.IsNaN(v) && !float.IsInfinity(v);","tryCatchPattern":"try\n{\n    value = animation.GetCurrentValue(origin, destination, clock);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"origin\"))\n{\n    value = destination; // finite fallback\n}","preventionTips":["Always set From/To on SingleAnimation so defaults are never validated","Check float.IsFinite on base values from data bindings before animating","Set Binding.FallbackValue to avoid NaN from failed bindings","Guard divisions that feed animated properties"],"tags":["wpf","animation","nan","argument-validation"],"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-22T01:17:13.364Z"}