{"record":{"id":"c0f4f804d407844a","repo":"dotnet/wpf","slug":"sr-invalidminmaxforbutton","errorCode":null,"errorMessage":"SR.InvalidMinMaxForButton","messagePattern":"SR\\.InvalidMinMaxForButton","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs","lineNumber":381,"sourceCode":"                    _pressureFactor = 0.0f;\n                }\n                else\n                {\n                    _pressureFactor = (float)(Convert.ToSingle(min + value) / Convert.ToSingle(max));\n                }\n            }\n            else\n            {\n                int propertyIndex = this.Description.GetPropertyIndex(stylusPointProperty.Id);\n                if (-1 == propertyIndex)\n                {\n                    throw new ArgumentException(SR.InvalidStylusPointProperty, \"propertyId\");\n                }\n                if (stylusPointProperty.IsButton)\n                {\n                    if (value < 0 || value > 1)\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(value), SR.InvalidMinMaxForButton);\n                    }\n\n                    if (copyBeforeWrite)\n                    {\n                        CopyAdditionalData();\n                    }\n\n                    //\n                    // we get button data from a single int in the array\n                    //\n                    int buttonData = _additionalValues[_additionalValues.Length - 1];\n                    int buttonBitPosition = this.Description.GetButtonBitPosition(stylusPointProperty);\n                    int bit = 1 << buttonBitPosition;\n                    if (value == 0)\n                    {\n                        //turn the bit off\n                        buttonData &= ~bit;\n                    }","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs#L363-L399","documentation":"StylusPoint.SetPropertyValue throws ArgumentOutOfRangeException when setting a button property (stylusPointProperty.IsButton is true) to a value other than 0 or 1. Button data is packed into a single int where each button occupies one bit, so only 0 (up) and 1 (down) are valid.","triggerScenarios":"Calling point.SetPropertyValue(barrelButtonProperty, 2) or any value < 0 or > 1 on a property where IsButton is true.","commonSituations":"Passing raw button state as an integer count or bitmask (e.g. 3 meaning two buttons pressed) instead of setting each button property individually to 0 or 1.","solutions":["Pass only 0 or 1 as the value for button properties; unpack multi-button bitmasks and set each button separately.","Coerce with Math.Clamp(value, 0, 1) or bool conversion ((int)(rawState != 0)) before calling.","Catch ArgumentOutOfRangeException when processing untrusted input values."],"exampleFix":"// before\npoint.SetPropertyValue(tipButton, buttonBitmask);\n// after\nbool isPressed = (buttonBitmask & 0x1) != 0;\npoint.SetPropertyValue(tipButton, isPressed ? 1 : 0);","handlingStrategy":"validation","validationCode":"if (value >= 0 && value <= 1)\n{\n    point.SetPropertyValue(buttonProp, value);\n}","typeGuard":"static bool IsValidButtonValue(int v) => v == 0 || v == 1;","tryCatchPattern":"try { point.SetPropertyValue(buttonProp, value); }\ncatch (ArgumentOutOfRangeException) { /* unpack bitmask properly */ }","preventionTips":["Only pass 0 or 1 for button properties","Convert bool button state explicitly with ? 1 : 0","Unpack multi-button bitmasks into per-button assignments"],"tags":["wpf","stylus","argumentoutofrange","button"],"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-21T21:30:21.729Z"}