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
- 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.
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
- Limit logical buttons to the supported maximum
- Fold extra hardware buttons into fewer logical buttons
- Handle surplus buttons outside the stylus pipeline
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
- SR.IncompatibleStylusPointDescriptions
- SR.InvalidIsButtonForId
- SR.InvalidIsButtonForId2
- SR.InvalidStylusPointDescription
- SR.InvalidStylusPointDescriptionButtonsMustBeLast
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)