{"record":{"id":"2b49e9e0e5c9413b","repo":"dotnet/wpf","slug":"sr-animation-invalid-defaultvalue-animationtemplate","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/WpfGfx/codegen/mcg/generators/AnimationTemplate.cs","lineNumber":421,"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.IsValidAnimationValue[[instance.TypeName]](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.IsValidAnimationValue[[instance.TypeName]](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":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationTemplate.cs#L403-L439","documentation":"Generated animation classes (from AnimationTemplate) validate the default origin value via AnimatedTypeHelpers.IsValidAnimationValue<T> when Go() is called with validateOrigin. If the caller-supplied defaultOriginValue is not a valid animation value for the animated type (e.g. NaN or Infinity for a double), Go() throws InvalidOperationException with SR.Animation_Invalid_DefaultValue, naming the animation type, 'origin', and the offending value.","triggerScenarios":"Calling animation.Go(new DoubleAnimation(...), defaultOriginValue: double.NaN/PositiveInfinity, ...) or the generated Go(origin, destination) overload with an invalid origin while validateOrigin is true; data-bound origin values that resolved to NaN.","commonSituations":"Binding animation origins to computed geometry results (e.g. NaN from a divide by zero in layout math); passing unset (NaN) struct fields as origin values.","solutions":["Validate the origin value before calling Go(): reject double.NaN/Infinity (use double.IsFinite).","Let the animation compute the origin itself (pass the overload without a default origin value).","Trace where the origin value is computed and fix the NaN-producing calculation.","Clamp/sanitize data-bound values via a value converter."],"exampleFix":"// before\nanim.Go(null, new object[] { double.NaN, 100.0 }); // invalid origin\n// after\nif (double.IsFinite(origin))\n    anim.Go(null, new object[] { origin, 100.0 });","handlingStrategy":"validation","validationCode":"if (!double.IsFinite(origin))\n    origin = 0.0; // or skip the animation\nanim.Go(null, new object[] { origin, destination });","typeGuard":"bool IsValidAnimationOrigin(double v) => double.IsFinite(v);","tryCatchPattern":"try { anim.Go(null, new object[] { origin, dest }); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"origin\"))\n{ log.Warn(\"Invalid animation origin\", ex); }","preventionTips":["Sanitize computed values (NaN/Infinity) before using them as animation origins","Prefer the Go overload that derives the origin from the current property value","Use value converters on data-bound animation values to coerce invalid values"],"tags":["animation","wpf","invalid-value","generated-code"],"backgroundTag":"value-out-of-range","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"}