dotnet/wpf · error · ArgumentException

SR.InvalidStylusPointDescriptionTooManyButtons

Error message

SR.InvalidStylusPointDescriptionTooManyButtons

What it means

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.

Solutions

  1. Reduce the number of button properties to MaximumButtonCount or fewer; map extra hardware buttons to fewer logical buttons.
  2. Represent extra buttons outside the StylusPointDescription, e.g. handle them at the device-driver or raw-input layer.
  3. Combine multiple hardware buttons into one StylusPointProperty with a value field instead of one button bit each.

Example fix

// before
var buttons = deviceButtons.Select(b => new StylusPointPropertyInfo(new StylusPointProperty(b.Guid, true))).ToArray();
var desc = new StylusPointDescription(required.Concat(buttons).ToArray()); // too many buttons
// after
var buttons = deviceButtons.Take(MaximumButtonCount).Select(b => new StylusPointPropertyInfo(new StylusPointProperty(b.Guid, true))).ToArray();
var desc = new StylusPointDescription(required.Concat(buttons).ToArray());
Defensive patterns

Strategy: validation

Validate before calling

int buttonCount = infos.Count(i => i.IsButton);
if (buttonCount > 32) { /* trim or split buttons */ }

Try / catch

try { var desc = new StylusPointDescription(infos); }
catch (ArgumentException) { /* drop excess buttons and retry */ }

Prevention

When it happens

Trigger: Calling new StylusPointDescription(infos) where the count of entries with IsButton == true exceeds MaximumButtonCount.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/6cee30597b437450. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPointDescription.cs:89

                    throw new ArgumentException(SR.InvalidStylusPointDescriptionDuplicatesFound, nameof(stylusPointPropertyInfos));
                }
                if (infos[x].IsButton)
                {
                    buttonCount++;
                }
                else
                {
                    //this is not a button, make sure we haven't seen one before
                    if (buttonCount > 0)
                    {
                        throw new ArgumentException(SR.InvalidStylusPointDescriptionButtonsMustBeLast, nameof(stylusPointPropertyInfos));
                    }
                }
                seenIds.Add(infos[x].Id);
            }
            if (buttonCount > MaximumButtonCount)
            {
                throw new ArgumentException(SR.InvalidStylusPointDescriptionTooManyButtons, nameof(stylusPointPropertyInfos));
            }

            _buttonCount = buttonCount;
            _stylusPointPropertyInfos = infos.ToArray();
        }

        /// <summary>
        /// StylusPointDescription
        /// </summary>
        /// <param name="stylusPointPropertyInfos">stylusPointPropertyInfos</param>
        /// <param name="originalPressureIndex">originalPressureIndex - does the digitizer really support pressure?  If so, the index this was at</param>
        internal StylusPointDescription(IEnumerable<StylusPointPropertyInfo> stylusPointPropertyInfos, int originalPressureIndex)
            : this (stylusPointPropertyInfos)
        {
            _originalPressureIndex = originalPressureIndex;
        }

        /// <summary>

View on GitHub (pinned to 81131a70a4)