{"record":{"id":"fd253524bb3b6e1e","repo":"dotnet/wpf","slug":"sr-animation-keyspline-invalidvalue","errorCode":null,"errorMessage":"SR.Animation_KeySpline_InvalidValue","messagePattern":"SR\\.Animation_KeySpline_InvalidValue","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs","lineNumber":57,"sourceCode":"        /// <param name=\"y1\">y value for the 0,0 endpoint's control point</param>\n        /// <param name=\"x2\">x value for the 1,1 endpoint's control point</param>\n        /// <param name=\"y2\">y value for the 1,1 endpoint's control point</param>\n        public KeySpline(double x1, double y1, double x2, double y2)\n            : this(new Point(x1, y1), new Point(x2, y2))\n        {\n        }\n\n        /// <summary>\n        /// Point constructor\n        /// </summary>\n        /// <param name=\"controlPoint1\">the control point for the 0,0 endpoint</param>\n        /// <param name=\"controlPoint2\">the control point for the 1,1 endpoint</param>\n        public KeySpline(Point controlPoint1, Point controlPoint2)\n            : base()\n        {\n            if (!IsValidControlPoint(controlPoint1))\n            {\n                throw new ArgumentException(SR.Format(\n                    SR.Animation_KeySpline_InvalidValue,\n                    \"controlPoint1\",\n                    controlPoint1));\n            }\n\n            if (!IsValidControlPoint(controlPoint2))\n            {\n                throw new ArgumentException(SR.Format(\n                    SR.Animation_KeySpline_InvalidValue,\n                    \"controlPoint2\",\n                    controlPoint2));\n            }\n\n            _controlPoint1 = controlPoint1;\n            _controlPoint2 = controlPoint2;\n\n            _isDirty = true;\n        }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs#L39-L75","documentation":"The KeySpline(Point, Point) constructor throws ArgumentException (SR.Animation_KeySpline_InvalidValue) because KeySpline control points must lie in the unit square: each X and Y coordinate must be between 0.0 and 1.0 inclusive. This is required because a key spline defines a Bezier timing curve from (0,0) to (1,1).","triggerScenarios":"new KeySpline(cp1, cp2) where either point has an X or Y coordinate < 0.0 or > 1.0 (e.g. new KeySpline(new Point(0.5, 1.5), new Point(0,0))).","commonSituations":"Building a KeySplineKeyFrame with easing parameters parsed from user config/XAML where values were percentages (0-100) instead of fractions (0-1); copying spline values from CSS cubic-bezier-like sources with out-of-range coordinates; arithmetic mistakes generating control points.","solutions":["Clamp both control points into [0,1] on each axis before constructing: Math.Clamp(v, 0.0, 1.0).","Verify the units: control points are fractions of progress/time, not percentages.","Validate inputs before construction with the same rule KeySpline uses (all coords within 0..1) and surface a friendly error.","Wrap construction in try/catch (ArgumentException) and fall back to a known-good spline such as (0,0)-(1,1) (linear)."],"exampleFix":"// before\nvar spline = new KeySpline(new Point(0.4, 80), new Point(0.6, 95)); // percent values\n// after\nstatic Point Clamped(Point p) => new Point(Math.Clamp(p.X, 0, 1), Math.Clamp(p.Y, 0, 1));\nvar spline = new KeySpline(Clamped(new Point(0.4, 0.8)), Clamped(new Point(0.6, 0.95)));","handlingStrategy":"validation","validationCode":"static bool IsValidControlPoint(Point p) => p.X >= 0 && p.X <= 1 && p.Y >= 0 && p.Y <= 1;\nif (!IsValidControlPoint(cp1) || !IsValidControlPoint(cp2))\n    throw new ArgumentException(\"KeySpline control points must be within [0,1] on both axes.\");","typeGuard":"static Point ClampToUnitSquare(Point p) => new Point(Math.Clamp(p.X, 0.0, 1.0), Math.Clamp(p.Y, 0.0, 1.0));","tryCatchPattern":"KeySpline spline;\ntry { spline = new KeySpline(cp1, cp2); }\ncatch (ArgumentException)\n{\n    spline = new KeySpline(new Point(0, 0), new Point(1, 1)); // linear fallback\n}","preventionTips":["Remember control points are 0..1 fractions, never 0..100 percents","Clamp points loaded from config or external easing definitions","Constrain spline-editor UI inputs to [0,1]","Centralize KeySpline construction in one validated factory method"],"tags":["wpf","animation","keyspline","argument-validation"],"backgroundTag":"invalid-constructor-argument","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"}