{"record":{"id":"6cee30597b437450","repo":"dotnet/wpf","slug":"sr-invalidstyluspointdescriptiontoomanybuttons","errorCode":null,"errorMessage":"SR.InvalidStylusPointDescriptionTooManyButtons","messagePattern":"SR\\.InvalidStylusPointDescriptionTooManyButtons","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPointDescription.cs","lineNumber":89,"sourceCode":"                    throw new ArgumentException(SR.InvalidStylusPointDescriptionDuplicatesFound, nameof(stylusPointPropertyInfos));\n                }\n                if (infos[x].IsButton)\n                {\n                    buttonCount++;\n                }\n                else\n                {\n                    //this is not a button, make sure we haven't seen one before\n                    if (buttonCount > 0)\n                    {\n                        throw new ArgumentException(SR.InvalidStylusPointDescriptionButtonsMustBeLast, nameof(stylusPointPropertyInfos));\n                    }\n                }\n                seenIds.Add(infos[x].Id);\n            }\n            if (buttonCount > MaximumButtonCount)\n            {\n                throw new ArgumentException(SR.InvalidStylusPointDescriptionTooManyButtons, nameof(stylusPointPropertyInfos));\n            }\n\n            _buttonCount = buttonCount;\n            _stylusPointPropertyInfos = infos.ToArray();\n        }\n\n        /// <summary>\n        /// StylusPointDescription\n        /// </summary>\n        /// <param name=\"stylusPointPropertyInfos\">stylusPointPropertyInfos</param>\n        /// <param name=\"originalPressureIndex\">originalPressureIndex - does the digitizer really support pressure?  If so, the index this was at</param>\n        internal StylusPointDescription(IEnumerable<StylusPointPropertyInfo> stylusPointPropertyInfos, int originalPressureIndex)\n            : this (stylusPointPropertyInfos)\n        {\n            _originalPressureIndex = originalPressureIndex;\n        }\n\n        /// <summary>","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPointDescription.cs#L71-L107","documentation":"The StylusPointDescription constructor limits the number of button properties to MaximumButtonCount. This ArgumentException is thrown when the supplied collection contains more button StylusPointPropertyInfos than that maximum, since the packed bit layout for buttons in StylusPoint packet data can only hold a fixed number of button bits.","triggerScenarios":"Calling new StylusPointDescription(infos) where the count of entries with IsButton == true exceeds MaximumButtonCount.","commonSituations":"Describing a multi-button device (e.g. art tablets with many programmable barrel buttons) by adding a property per button; generating button infos from a device capability report with more buttons than WPF supports.","solutions":["Reduce the number of button properties to MaximumButtonCount or fewer; map extra hardware buttons to fewer logical buttons.","Represent extra buttons outside the StylusPointDescription, e.g. handle them at the device-driver or raw-input layer.","Combine multiple hardware buttons into one StylusPointProperty with a value field instead of one button bit each."],"exampleFix":"// before\nvar buttons = deviceButtons.Select(b => new StylusPointPropertyInfo(new StylusPointProperty(b.Guid, true))).ToArray();\nvar desc = new StylusPointDescription(required.Concat(buttons).ToArray()); // too many buttons\n// after\nvar buttons = deviceButtons.Take(MaximumButtonCount).Select(b => new StylusPointPropertyInfo(new StylusPointProperty(b.Guid, true))).ToArray();\nvar desc = new StylusPointDescription(required.Concat(buttons).ToArray());","handlingStrategy":"validation","validationCode":"int buttonCount = infos.Count(i => i.IsButton);\nif (buttonCount > 32) { /* trim or split buttons */ }","typeGuard":null,"tryCatchPattern":"try { var desc = new StylusPointDescription(infos); }\ncatch (ArgumentException) { /* drop excess buttons and retry */ }","preventionTips":["Limit logical buttons to the supported maximum","Fold extra hardware buttons into fewer logical buttons","Handle surplus buttons outside the stylus pipeline"],"tags":["wpf","stylus","limit","argument-exception"],"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"}