{"record":{"id":"7380f1461468bc96","repo":"dotnet/wpf","slug":"sr-animation-keyspline-invalidvalue-controlpoint2","errorCode":null,"errorMessage":"SR.Animation_KeySpline_InvalidValue (ControlPoint2)","messagePattern":"SR\\.Animation_KeySpline_InvalidValue \\(ControlPoint2\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs","lineNumber":199,"sourceCode":"        /// \n        /// </summary>\n        public Point ControlPoint2\n        {\n            get\n            {\n                ReadPreamble();\n\n                return _controlPoint2;\n            }\n            set\n            {\n                WritePreamble();\n\n                if (value != _controlPoint2)\n                {\n                    if (!IsValidControlPoint(value))\n                    {\n                        throw new ArgumentException(SR.Format(\n                            SR.Animation_KeySpline_InvalidValue,\n                            \"ControlPoint2\",\n                            value));\n                    }\n\n                    _controlPoint2 = value;\n\n                    WritePostscript();\n                }\n            }\n        }\n\n        /// <summary>\n        /// Calculates spline progress from a linear progress.\n        /// </summary>\n        /// <param name=\"linearProgress\">the linear progress</param>\n        /// <returns>the spline progress</returns>\n        public double GetSplineProgress(double linearProgress)","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs#L181-L217","documentation":"The KeySpline.ControlPoint2 property setter throws ArgumentException (SR.Animation_KeySpline_InvalidValue) when the assigned point has any X or Y coordinate outside [0,1]. Like ControlPoint1, the value is only written after IsValidControlPoint passes, keeping the timing curve inside the unit square.","triggerScenarios":"keySpline.ControlPoint2 = new Point(x, y) with x or y < 0.0 or > 1.0, e.g. from an easing editor or generated animation code.","commonSituations":"Easing-curve editors without input clamping; importing spline data from formats allowing overshoot (e.g. raw CSS cubic-bezier x-values outside [0,1]); percentage-based configuration.","solutions":["Clamp both coordinates into [0,1] before setting ControlPoint2.","Validate in the input layer (slider ranges, numeric updown min/max) so out-of-range values never reach the setter.","Catch ArgumentException around the assignment and revert to the previous value.","Recreate the KeySpline via the constructor with both points validated together."],"exampleFix":"// before\nspline.ControlPoint2 = parsedPoint;\n// after\nspline.ControlPoint2 = new Point(Math.Clamp(parsedPoint.X, 0, 1), Math.Clamp(parsedPoint.Y, 0, 1));","handlingStrategy":"validation","validationCode":"if (value.X < 0 || value.X > 1 || value.Y < 0 || value.Y > 1)\n    value = new Point(Math.Clamp(value.X, 0, 1), Math.Clamp(value.Y, 0, 1));\nspline.ControlPoint2 = value;","typeGuard":"static Point SafeControlPoint2(Point p) => new Point(Math.Clamp(p.X, 0.0, 1.0), Math.Clamp(p.Y, 0.0, 1.0));","tryCatchPattern":"Point previous = spline.ControlPoint2;\ntry { spline.ControlPoint2 = candidate; }\ncatch (ArgumentException) { spline.ControlPoint2 = previous; }","preventionTips":["Apply the same [0,1] clamp helper to both control points","Check imported cubic-bezier data: some formats allow x outside [0,1]","Constrain UI numeric inputs before they reach the setter","Prefer recreating the KeySpline with validated points over in-place mutation"],"tags":["wpf","animation","keyspline","property-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-21T21:30:21.729Z"}