dotnet/wpf · error · ArgumentException
SR.InvalidIsButtonForId2
Error message
SR.InvalidIsButtonForId2
What it means
The complementary check in StylusPointProperty.Initialize: if the identifier is a known non-button Guid (a standard axis like X, Y, NormalPressure) but isButton is true, an ArgumentException naming isButton is thrown. Known Guids have fixed semantics, so marking a standard axis property as a button is invalid.
Solutions
- Pass false for known non-button Guids; only button Guids (TipButton/BarrelButton) accept true.
- For custom buttons use a newly generated Guid (Guid.NewGuid) with isButton true rather than a known Guid.
- Derive the flag: new StylusPointProperty(id, StylusPointPropertyIds.IsKnownButton(id)).
Example fix
// before var prop = new StylusPointProperty(StylusPointPropertyIds.X, true); // after var prop = new StylusPointProperty(StylusPointPropertyIds.X, false);
Defensive patterns
Strategy: validation
Validate before calling
bool valid = !isButton || StylusPointPropertyIds.IsKnownButton(id);
Try / catch
try { var p = new StylusPointProperty(id, isButton); }
catch (ArgumentException) { p = new StylusPointProperty(id, false); } Prevention
- Pass isButton true only for known button Guids or fresh custom Guids
- Never mark standard axis Guids (X, Y, NormalPressure) as buttons
- Validate capability lists before mapping to properties
When it happens
Trigger: Calling new StylusPointProperty(StylusPointPropertyIds.X /* or any known non-button Guid */, true).
Common situations: Wrapping raw device Guids with isButton true whenever the packet field looks boolean; bulk-constructing properties from a device capability list with an incorrect button flag column; trying to create a custom button with an accidental known-Guid value.
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.InvalidIsButtonForId
- 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/d4783a0f93aab95b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPointProperty.cs:63
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>
public Guid Id
{
get { return _id; }
}
/// <summary>
/// IsButton
/// </summary>View on GitHub (pinned to 81131a70a4)