{"record":{"id":"17fbc8b08ef23600","repo":"dotnet/wpf","slug":"sr-invalidstyluspointcollectionzerocount","errorCode":null,"errorMessage":"SR.InvalidStylusPointCollectionZeroCount","messagePattern":"SR\\.InvalidStylusPointCollectionZeroCount","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke.cs","lineNumber":50,"sourceCode":"        /// <param name=\"stylusPoints\">StylusPointCollection that makes up the stroke</param>\n        /// <param name=\"drawingAttributes\">drawingAttributes</param>\n        public Stroke(StylusPointCollection stylusPoints, DrawingAttributes drawingAttributes)\n            : this(stylusPoints, drawingAttributes, null)\n        {\n        }\n\n        /// <summary>Create a stroke from a StylusPointCollection</summary>\n        /// <remarks>\n        /// </remarks>\n        /// <param name=\"stylusPoints\">StylusPointCollection that makes up the stroke</param>\n        /// <param name=\"drawingAttributes\">drawingAttributes</param>\n        /// <param name=\"extendedProperties\">extendedProperties</param>\n        internal Stroke(StylusPointCollection stylusPoints, DrawingAttributes drawingAttributes, ExtendedPropertyCollection extendedProperties)\n        {\n            ArgumentNullException.ThrowIfNull(stylusPoints);\n            if (stylusPoints.Count == 0)\n            {\n                throw new ArgumentException(SR.InvalidStylusPointCollectionZeroCount, nameof(stylusPoints));\n            }\n            ArgumentNullException.ThrowIfNull(drawingAttributes);\n\n            _drawingAttributes = drawingAttributes;\n            _stylusPoints = stylusPoints;\n            _extendedProperties = extendedProperties;\n\n            Initialize();\n        }\n\n        /// <summary>\n        /// Internal helper to set up listeners, called by ctor and by Clone\n        /// </summary>\n        private void Initialize()\n        {\n            _drawingAttributes.AttributeChanged += new PropertyDataChangedEventHandler(DrawingAttributes_Changed);\n            _stylusPoints.Changed += new EventHandler(StylusPoints_Changed);\n            _stylusPoints.CountGoingToZero += new CancelEventHandler(StylusPoints_CountGoingToZero);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke.cs#L32-L68","documentation":"The internal Stroke constructor requires a StylusPointCollection with at least one point. An empty stroke has no geometry, bounds, or drawable path, so WPF rejects empty point collections at construction rather than creating a degenerate Stroke. ArgumentException is thrown naming the stylusPoints parameter.","triggerScenarios":"Calling any public Stroke constructor (Stroke(StylusPointCollection), Stroke(StylusPointCollection, DrawingAttributes)) with a StylusPointCollection whose Count == 0, e.g. new Stroke(new StylusPointCollection()).","commonSituations":"Building strokes programmatically from captured stylus data that produced no samples; converting persisted ink where a stroke's point list was empty; test fixtures constructing default strokes.","solutions":["Guard before constructing: only create a Stroke when stylusPoints.Count > 0","If empty input is expected, skip stroke creation or use an empty StrokeCollection instead of an empty Stroke","Populate the StylusPointCollection with at least one StylusPoint before passing it in"],"exampleFix":"// before\nvar stroke = new Stroke(stylusPoints); // throws if empty\n// after\nif (stylusPoints.Count == 0) return null;\nvar stroke = new Stroke(stylusPoints);","handlingStrategy":"validation","validationCode":"if (stylusPoints == null || stylusPoints.Count == 0) return null; // skip stroke creation","typeGuard":"bool IsValidStrokeSource(StylusPointCollection p) => p != null && p.Count > 0;","tryCatchPattern":"try { var stroke = new Stroke(stylusPoints); } catch (ArgumentException ex) when (ex.ParamName == \"stylusPoints\") { /* handle empty collection */ }","preventionTips":["Never construct strokes from potentially empty captured point lists","Represent absence of ink with an empty StrokeCollection, not an empty Stroke","Assert non-empty point data when deserializing persisted ink"],"tags":["wpf","ink","argument-exception","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"}