{"record":{"id":"c048fe3ebf1f7fd8","repo":"dotnet/wpf","slug":"sr-invalidemptyarray","errorCode":null,"errorMessage":"SR.InvalidEmptyArray","messagePattern":"SR\\.InvalidEmptyArray","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Ink/Events.cs","lineNumber":312,"sourceCode":"        /// <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; }\n        }\n\n        /// <summary>\n        /// TBD\n        /// </summary>\n        /// <returns></returns>\n        public ReadOnlyCollection<GestureRecognitionResult> GetGestureRecognitionResults()","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Ink/Events.cs#L294-L330","documentation":"The gestureRecognitionResults parameter of InkCanvasGestureEventArgs must yield at least one GestureRecognitionResult. After copying the IEnumerable into a list, a Count == 0 check throws ArgumentException (SR.InvalidEmptyArray) because the event must carry at least one recognition result.","triggerScenarios":"new InkCanvasGestureEventArgs(strokes, Array.Empty<GestureRecognitionResult>()), an empty results list from a recognizer that found no candidates, or a lazy IEnumerable that enumerates to zero items.","commonSituations":"Wrapping a gesture recognizer that returns no matches without special-casing the 'no gesture' outcome; passing the result of a LINQ query that filtered everything out; test fixtures with stub recognizers returning empty lists.","solutions":["Only construct InkCanvasGestureEventArgs when the recognizer produced at least one result; otherwise take the 'no gesture' code path.","If recognition genuinely found nothing, add a fallback GestureRecognitionResult (e.g., ApplicationGesture.NoGesture) instead of an empty list.","Materialize and check results.Count before calling the constructor."],"exampleFix":"// before\nvar args = new InkCanvasGestureEventArgs(strokes, recognizerResults);\n\n// after\nvar results = recognizerResults.ToList();\nif (results.Count == 0)\n    results.Add(new GestureRecognitionResult(0.0, ApplicationGesture.NoGesture));\nvar args = new InkCanvasGestureEventArgs(strokes, results);","handlingStrategy":"validation","validationCode":"var results = gestureRecognitionResults?.ToList();\nif (results == null || results.Count == 0)\n    return; // no recognition results: take no-gesture path\nvar args = new InkCanvasGestureEventArgs(strokes, results);","typeGuard":"bool HasRecognitionResults(IEnumerable<GestureRecognitionResult> r) => r != null && r.Any();","tryCatchPattern":"try { var args = new InkCanvasGestureEventArgs(strokes, results); }\ncatch (ArgumentException ex) when (ex.ParamName == \"gestureRecognitionResults\")\n{ /* recognizer produced nothing; treat as no gesture */ }","preventionTips":["Materialize the results enumerable and count it before constructing the args.","Add a NoGesture fallback result when the recognizer found no candidates.","Ensure stub/mock recognizers in tests return at least one result."],"tags":["wpf","inkcanvas","gesture","argumentexception","empty-array"],"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"}