{"record":{"id":"7d5650b239a17073","repo":"dotnet/wpf","slug":"sr-invalidemptystrokecollection","errorCode":null,"errorMessage":"SR.InvalidEmptyStrokeCollection","messagePattern":"SR\\.InvalidEmptyStrokeCollection","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Ink/Events.cs","lineNumber":305,"sourceCode":"    /// </summary>\n    public class InkCanvasGestureEventArgs : RoutedEventArgs\n    {\n        private StrokeCollection _strokes;\n        private List<GestureRecognitionResult> _gestureRecognitionResults;\n        private bool                _cancel;\n\n        /// <summary>\n        /// TBD\n        /// </summary>\n        /// <param name=\"strokes\">strokes</param>\n        /// <param name=\"gestureRecognitionResults\">gestureRecognitionResults</param>\n        public InkCanvasGestureEventArgs(StrokeCollection strokes, IEnumerable<GestureRecognitionResult> gestureRecognitionResults)\n            : base(InkCanvas.GestureEvent)\n        {\n            ArgumentNullException.ThrowIfNull(strokes);\n            if (strokes.Count < 1)\n            {\n                throw new ArgumentException(SR.InvalidEmptyStrokeCollection, nameof(strokes));\n            }\n            ArgumentNullException.ThrowIfNull(gestureRecognitionResults);\n            List<GestureRecognitionResult> results = \n                new List<GestureRecognitionResult>(gestureRecognitionResults);\n            if (results.Count == 0)\n            {\n                throw new ArgumentException(SR.InvalidEmptyArray, nameof(gestureRecognitionResults));\n            }\n            _strokes = strokes;\n            _gestureRecognitionResults = results;\n        }\n\n        /// <summary>\n        /// TBD\n        /// </summary>\n        public StrokeCollection Strokes\n        {\n            get { return _strokes; }","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Ink/Events.cs#L287-L323","documentation":"InkCanvasGestureEventArgs requires the strokes parameter to contain at least one Stroke. An empty StrokeCollection fails the strokes.Count < 1 guard and throws ArgumentException (SR.InvalidEmptyStrokeCollection) because a gesture event with no ink is meaningless for recognition.","triggerScenarios":"new InkCanvasGestureEventArgs(new StrokeCollection(), results) or passing a collection whose strokes were all removed/erased before the gesture event args were built.","commonSituations":"Custom gesture handling where the user's stroke was deleted between capture and arg construction; programmatically raising the Gesture event with no ink; replay/test harnesses building args from empty input buffers.","solutions":["Check strokes.Count > 0 before constructing the event args and skip raising the gesture event when empty.","Erase strokes only after gesture processing completes, not before constructing the args.","In the Gesture handler, guard with if (e == null || strokeSource.Count == 0) return; when synthesizing args yourself."],"exampleFix":"// before\nvar args = new InkCanvasGestureEventArgs(collectedStrokes, results);\nRaiseEvent(args);\n\n// after\nif (collectedStrokes.Count > 0)\n{\n    var args = new InkCanvasGestureEventArgs(collectedStrokes, results);\n    RaiseEvent(args);\n}","handlingStrategy":"validation","validationCode":"if (strokes == null || strokes.Count < 1)\n    return; // skip gesture event\nvar args = new InkCanvasGestureEventArgs(strokes, results);","typeGuard":"bool HasStrokes(StrokeCollection sc) => sc is { Count: > 0 };","tryCatchPattern":"try { var args = new InkCanvasGestureEventArgs(strokes, results); RaiseEvent(args); }\ncatch (ArgumentException ex) when (ex.ParamName == \"strokes\")\n{ /* no ink captured; skip gesture processing */ }","preventionTips":["Check strokes.Count before constructing gesture event args.","Erase/remove strokes only after gesture handling completes.","Never raise the Gesture event programmatically with an empty collection."],"tags":["wpf","inkcanvas","gesture","argumentexception","empty-collection"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}