{"record":{"id":"3de36c8225e33e9f","repo":"dotnet/wpf","slug":"sr-invalidadditionaldataforstyluspoint","errorCode":null,"errorMessage":"SR.InvalidAdditionalDataForStylusPoint","messagePattern":"SR\\.InvalidAdditionalDataForStylusPoint","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs","lineNumber":119,"sourceCode":"                ArgumentNullException.ThrowIfNull(stylusPointDescription);\n\n                //\n                // additionalValues can be null if PropertyCount == 3 (X, Y, P)\n                //\n                if (stylusPointDescription.PropertyCount > StylusPointDescription.RequiredCountOfProperties)\n                {\n                    ArgumentNullException.ThrowIfNull(additionalValues);\n                }\n\n                if (additionalValues != null)\n                {\n                    ReadOnlyCollection<StylusPointPropertyInfo> properties\n                        = stylusPointDescription.GetStylusPointProperties();\n\n                    int expectedAdditionalValues = properties.Count - StylusPointDescription.RequiredCountOfProperties; //for x, y, pressure\n                    if (additionalValues.Length != expectedAdditionalValues)\n                    {\n                        throw new ArgumentException(SR.InvalidAdditionalDataForStylusPoint, nameof(additionalValues));\n                    }\n\n                    //\n                    // any buttons passed in must each be in their own int.  We need to \n                    // pack them all into one int here\n                    //\n                    int[] newAdditionalValues =\n                        new int[stylusPointDescription.GetExpectedAdditionalDataCount()];\n\n                    _additionalValues = newAdditionalValues;\n                    for (int i = StylusPointDescription.RequiredCountOfProperties, j = 0; i < properties.Count; i++, j++)\n                    {\n                        //\n                        // use SetPropertyValue, it validates buttons, but does not copy the \n                        // int[] on writes (since we pass the bool flag)\n                        //\n                        SetPropertyValue(properties[i], additionalValues[j], copyBeforeWrite: false);\n                    }","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs#L101-L137","documentation":"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.","triggerScenarios":"new StylusPoint(x, y, pressureFactor, stylusPointDescription, additionalValues, validateAdditionalData:true) where additionalValues.Length != (description property count - StylusPointDescription.RequiredCountOfProperties).","commonSituations":"Reusing an additionalValues array built for a different StylusPointDescription, forgetting buttons need one int per button, or a stale description after device configuration changed.","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."],"exampleFix":"// before\nvar point = new StylusPoint(x, y, 0.5f, description, new float[] { 1 });\n// after\nint expected = description.GetStylusPointProperties().Count - StylusPointDescription.RequiredCountOfProperties;\nvar additionalValues = new float[expected];\nvar point = new StylusPoint(x, y, 0.5f, description, additionalValues);","handlingStrategy":"validation","validationCode":"int expected = description.GetStylusPointProperties().Count - StylusPointDescription.RequiredCountOfProperties;\nif (additionalValues.Length != expected)\n    throw new ArgumentException($\"additionalValues must have {expected} entries\");","typeGuard":null,"tryCatchPattern":"try { var p = new StylusPoint(x, y, pf, description, additionalValues); }\ncatch (ArgumentException) { /* rebuild additionalValues for this description */ }","preventionTips":["Size additionalValues from the description, never hardcode","Keep one StylusPointDescription instance per point family","Allocate one slot per button when packing"],"tags":["wpf","stylus","argumentexception","array-length"],"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"}