{"record":{"id":"8086f82729b5c7eb","repo":"dotnet/wpf","slug":"sr-invalidisbuttonforid","errorCode":null,"errorMessage":"SR.InvalidIsButtonForId","messagePattern":"SR\\.InvalidIsButtonForId","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPointProperty.cs","lineNumber":55,"sourceCode":"            Initialize(stylusPointProperty.Id, stylusPointProperty.IsButton);\n        }\n\n        /// <summary>\n        /// Common ctor helper\n        /// </summary>\n        /// <param name=\"identifier\">identifier</param>\n        /// <param name=\"isButton\">isButton</param>\n        private void Initialize(Guid identifier, bool isButton)\n        {\n            //\n            // validate isButton for known guids\n            //\n            if (StylusPointPropertyIds.IsKnownButton(identifier))\n            {\n                if (!isButton)\n                {\n                    //error, this is a known button\n                    throw new ArgumentException(SR.InvalidIsButtonForId, nameof(isButton));\n                }\n            }\n            else\n            {\n                if (StylusPointPropertyIds.IsKnownId(identifier) && isButton)\n                {\n                    //error, this is a known guid that is NOT a button\n                    throw new ArgumentException(SR.InvalidIsButtonForId2, nameof(isButton));\n                }\n            }\n\n            _id = identifier;\n            _isButton = isButton;\n        }\n\n        /// <summary>\n        /// Id\n        /// </summary>","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPointProperty.cs#L37-L73","documentation":"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.","triggerScenarios":"Calling new StylusPointProperty(StylusPointPropertyIds.TipButton /* or another known button Guid */, false).","commonSituations":"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.","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."],"exampleFix":"// before\nvar prop = new StylusPointProperty(StylusPointPropertyIds.TipButton, false);\n// after\nvar prop = new StylusPointProperty(StylusPointPropertyIds.TipButton, true);","handlingStrategy":"validation","validationCode":"bool valid = !StylusPointPropertyIds.IsKnownButton(id) || isButton;","typeGuard":null,"tryCatchPattern":"try { var p = new StylusPointProperty(id, isButton); }\ncatch (ArgumentException) { p = new StylusPointProperty(id, !isButton); }","preventionTips":["Derive isButton via StylusPointPropertyIds.IsKnownButton(id)","Never hardcode the button flag for known Guids","Use predefined static StylusPointProperty instances where possible"],"tags":["wpf","stylus","argument-exception","enum"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}