dotnet/wpf · error · ArgumentException
SR.InvalidAdditionalDataForStylusPoint
Error message
SR.InvalidAdditionalDataForStylusPoint
What it means
The StylusPoint constructor throws ArgumentException when the additionalValues array length does not match the number of optional properties declared by the supplied StylusPointDescription. The description requires exactly one additional value per non-required property (required properties are x, y, and pressure), so a mismatched array cannot be mapped onto the description.
Solutions
- Build additionalValues with length equal to stylusPointDescription.GetStylusPointProperties().Count - StylusPointDescription.RequiredCountOfProperties.
- Ensure the same StylusPointDescription instance is used to create points and to interpret them.
- Pack each button value into its own slot in additionalValues before construction.
Example fix
// before
var point = new StylusPoint(x, y, 0.5f, description, new float[] { 1 });
// after
int expected = description.GetStylusPointProperties().Count - StylusPointDescription.RequiredCountOfProperties;
var additionalValues = new float[expected];
var point = new StylusPoint(x, y, 0.5f, description, additionalValues); Defensive patterns
Strategy: validation
Validate before calling
int expected = description.GetStylusPointProperties().Count - StylusPointDescription.RequiredCountOfProperties;
if (additionalValues.Length != expected)
throw new ArgumentException($"additionalValues must have {expected} entries"); Try / catch
try { var p = new StylusPoint(x, y, pf, description, additionalValues); }
catch (ArgumentException) { /* rebuild additionalValues for this description */ } Prevention
- Size additionalValues from the description, never hardcode
- Keep one StylusPointDescription instance per point family
- Allocate one slot per button when packing
When it happens
Trigger: new StylusPoint(x, y, pressureFactor, stylusPointDescription, additionalValues, validateAdditionalData:true) where additionalValues.Length != (description property count - StylusPointDescription.RequiredCountOfProperties).
Common situations: Reusing an additionalValues array built for a different StylusPointDescription, forgetting buttons need one int per button, or a stale description after device configuration changed.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.InvalidStylusPointProperty
- Can only countersign parts with Digital Signature…
- captureMode
- captureMode
- Duplicates not allowed - signature part already exists.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3de36c8225e33e9f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs:119
ArgumentNullException.ThrowIfNull(stylusPointDescription);
//
// additionalValues can be null if PropertyCount == 3 (X, Y, P)
//
if (stylusPointDescription.PropertyCount > StylusPointDescription.RequiredCountOfProperties)
{
ArgumentNullException.ThrowIfNull(additionalValues);
}
if (additionalValues != null)
{
ReadOnlyCollection<StylusPointPropertyInfo> properties
= stylusPointDescription.GetStylusPointProperties();
int expectedAdditionalValues = properties.Count - StylusPointDescription.RequiredCountOfProperties; //for x, y, pressure
if (additionalValues.Length != expectedAdditionalValues)
{
throw new ArgumentException(SR.InvalidAdditionalDataForStylusPoint, nameof(additionalValues));
}
//
// any buttons passed in must each be in their own int. We need to
// pack them all into one int here
//
int[] newAdditionalValues =
new int[stylusPointDescription.GetExpectedAdditionalDataCount()];
_additionalValues = newAdditionalValues;
for (int i = StylusPointDescription.RequiredCountOfProperties, j = 0; i < properties.Count; i++, j++)
{
//
// use SetPropertyValue, it validates buttons, but does not copy the
// int[] on writes (since we pass the bool flag)
//
SetPropertyValue(properties[i], additionalValues[j], copyBeforeWrite: false);
}View on GitHub (pinned to 81131a70a4)