{"record":{"id":"4aaf89b41f64cc11","repo":"AvaloniaUI/Avalonia","slug":"invalid-keyspline-x1-value-must-be-0-0-and","errorCode":null,"errorMessage":"Invalid KeySpline X1 value. Must be >= 0.0 and <= 1.0.","messagePattern":"Invalid KeySpline X1 value\\. Must be >= 0\\.0 and <= 1\\.0\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/KeySpline.cs","lineNumber":105,"sourceCode":"            return new KeySpline(tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble());\n        }\n\n        /// <summary>\n        /// X coordinate of the first control point\n        /// </summary>\n        public double ControlPointX1\n        {\n            get => _controlPointX1;\n            set\n            {\n                if (IsValidXValue(value))\n                {\n                    _controlPointX1 = value;\n                    _isDirty = true;\n                }\n                else\n                {\n                    throw new ArgumentException(\"Invalid KeySpline X1 value. Must be >= 0.0 and <= 1.0.\");\n                }\n            }\n        }\n\n        /// <summary>\n        /// Y coordinate of the first control point\n        /// </summary>\n        public double ControlPointY1\n        {\n            get => _controlPointY1;\n            set\n            {\n                _controlPointY1 = value;\n                _isDirty = true;\n            }\n        }\n\n        /// <summary>","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/KeySpline.cs#L87-L123","documentation":"Thrown by the ControlPointX1 setter when the supplied X1 value fails IsValidXValue, i.e. it is less than 0.0 or greater than 1.0. The constraint applies only to X coordinates because they represent normalized time on the bezier easing curve; Y coordinates (progress) are unconstrained.","triggerScenarios":"Assigning a number outside [0,1] to KeySpline.ControlPointX1 directly, or via reflection/serialization; parsing a malformed string into a KeySpline and then mutating X1.","commonSituations":"Treating the first control point like a free 2D point and setting X to values like 2.0 or -0.5; culture-related parse bugs producing NaN that then get assigned.","solutions":["Clamp the value to [0,1] before assigning: Math.Clamp(v, 0.0, 1.0).","Use the constructor KeySpline(x1,y1,x2,y2) only after validating, or set Y coordinates freely and keep X in range.","If the value comes from a string, validate with double.TryParse under InvariantCulture before assignment."],"exampleFix":"// before\nspline.ControlPointX1 = 1.2;\n\n// after\nspline.ControlPointX1 = Math.Clamp(1.2, 0.0, 1.0);","handlingStrategy":"validation","validationCode":"double x1 = Math.Clamp(rawX1, 0.0, 1.0);\nspline.ControlPointX1 = x1;","typeGuard":"static bool IsValidX(double v) => double.IsFinite(v) && v >= 0.0 && v <= 1.0;","tryCatchPattern":"try { spline.ControlPointX1 = v; }\ncatch (ArgumentException) { spline.ControlPointX1 = Math.Clamp(v, 0.0, 1.0); }","preventionTips":["Clamp user-provided X values before assignment.","Parse strings under InvariantCulture and reject NaN/Infinity."],"tags":["animation","keyspline","validation","argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}