dotnet/wpf · error · ArgumentException
SR.InvalidIsButtonForId
Error message
SR.InvalidIsButtonForId
What it means
The StylusPointProperty.Initialize method (called from the constructor) validates the isButton flag against the well-known Guid table. If the identifier is a known button Guid (e.g. TipButton, BarrelButton) but isButton is false, an ArgumentException naming isButton is thrown, because declaring a known button as a non-button is contradictory.
Solutions
- Pass true for Guids that are known buttons (StylusPointPropertyIds.IsKnownButton returns true for them).
- Derive the flag automatically: new StylusPointProperty(id, StylusPointPropertyIds.IsKnownButton(id)).
- Use the predefined static properties (e.g. StylusPointPropertyIds.TipButton entry in StylusPointProperty) instead of constructing manually.
Example fix
// before var prop = new StylusPointProperty(StylusPointPropertyIds.TipButton, false); // after var prop = new StylusPointProperty(StylusPointPropertyIds.TipButton, true);
Defensive patterns
Strategy: validation
Validate before calling
bool valid = !StylusPointPropertyIds.IsKnownButton(id) || isButton;
Try / catch
try { var p = new StylusPointProperty(id, isButton); }
catch (ArgumentException) { p = new StylusPointProperty(id, !isButton); } Prevention
- Derive isButton via StylusPointPropertyIds.IsKnownButton(id)
- Never hardcode the button flag for known Guids
- Use predefined static StylusPointProperty instances where possible
When it happens
Trigger: Calling new StylusPointProperty(StylusPointPropertyIds.TipButton /* or another known button Guid */, false).
Common situations: Re-creating standard properties from a Guid table loaded from device data and mislabeling buttons; using a loop over Guids with a hardcoded isButton value; copy-paste code that passes false for all properties.
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.InvalidIsButtonForId2
- captureMode
- InvalidEnumArgumentException(value, (int) value…
- is not a valid OS!
- SR.Animation_UnrecognizedHandoffBehavior
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8086f82729b5c7eb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPointProperty.cs:55
Initialize(stylusPointProperty.Id, stylusPointProperty.IsButton);
}
/// <summary>
/// Common ctor helper
/// </summary>
/// <param name="identifier">identifier</param>
/// <param name="isButton">isButton</param>
private void Initialize(Guid identifier, bool isButton)
{
//
// validate isButton for known guids
//
if (StylusPointPropertyIds.IsKnownButton(identifier))
{
if (!isButton)
{
//error, this is a known button
throw new ArgumentException(SR.InvalidIsButtonForId, nameof(isButton));
}
}
else
{
if (StylusPointPropertyIds.IsKnownId(identifier) && isButton)
{
//error, this is a known guid that is NOT a button
throw new ArgumentException(SR.InvalidIsButtonForId2, nameof(isButton));
}
}
_id = identifier;
_isButton = isButton;
}
/// <summary>
/// Id
/// </summary>View on GitHub (pinned to 81131a70a4)