{"record":{"id":"ed9e4ca76c49d97b","repo":"dotnet/wpf","slug":"sr-sceraseshape","errorCode":null,"errorMessage":"SR.SCEraseShape","messagePattern":"SR\\.SCEraseShape","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs","lineNumber":318,"sourceCode":"        {\n            if (!bounds.IsEmpty)\n            {\n                Erase(new Point[4] { bounds.TopLeft, bounds.TopRight, bounds.BottomRight, bounds.BottomLeft });\n            }\n        }\n\n\n        /// <summary>\n        /// Erases all ink hit by the contour of an erasing stroke\n        /// </summary>\n        /// <param name=\"eraserShape\">Shape of the eraser</param>\n        /// <param name=\"eraserPath\">a path making the spine of the erasing stroke </param>\n        public void Erase(IEnumerable<Point> eraserPath, StylusShape eraserShape)\n        {\n            // Check the input parameters\n            if (eraserShape == null)\n            {\n                throw new System.ArgumentNullException(SR.SCEraseShape);\n            }\n            if (eraserPath == null)\n            {\n                throw new System.ArgumentNullException(SR.SCErasePath);\n            }\n            if (IEnumerablePointHelper.GetCount(eraserPath) == 0)\n            {\n                return;\n            }\n\n            ErasingStroke erasingStroke = new ErasingStroke(eraserShape, eraserPath);\n            for (int i = 0; i < this.Count; i++)\n            {\n                Stroke stroke = this[i];\n\n                List<StrokeIntersection> intersections = new List<StrokeIntersection>();\n                erasingStroke.EraseTest(StrokeNodeIterator.GetIterator(stroke, stroke.DrawingAttributes), intersections);\n                StrokeCollection eraseResult = stroke.Erase(intersections.ToArray());","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs#L300-L336","documentation":"StrokeCollection.Erase(IEnumerable<Point> eraserPath, StylusShape eraserShape) requires a non-null eraser shape; a null shape throws ArgumentNullException whose message is SR.SCEraseShape. The shape defines the tip geometry (e.g. rectangle/ellipse) of the erasing stroke.","triggerScenarios":"Calling the shaped Erase overload with eraserShape == null, e.g. a StylusShape field never initialized, or a settings lookup that returned null when the eraser type is unknown.","commonSituations":"Custom eraser tools where the shape is created lazily on first stylus input but the erase call happens first; deserialized tool configuration missing the shape; refactors replacing a default shape with a nullable one.","solutions":["Construct a shape before calling: new EllipseStylusShape(w, h) or RectangleStylusShape","Guard: if (eraserShape == null) use a default shape","Initialize the tool state so the shape always exists when erasing is enabled"],"exampleFix":"// before\nstrokes.Erase(path, currentShape); // currentShape may be null\n// after\nvar shape = currentShape ?? new EllipseStylusShape(10, 10);\nstrokes.Erase(path, shape);","handlingStrategy":"type-guard","validationCode":"if (eraserShape == null) eraserShape = new EllipseStylusShape(10, 10);","typeGuard":"bool HasShape(StylusShape s) => s != null;","tryCatchPattern":"try { strokes.Erase(path, shape); } catch (ArgumentNullException) { strokes.Erase(path, new EllipseStylusShape(10, 10)); }","preventionTips":["Initialize tool shapes eagerly when the eraser tool is activated","Use non-nullable StylusShape fields with defaults","Never lazily create shapes during input handling"],"tags":["wpf","ink","argument-null","erase"],"backgroundTag":"null-argument","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"}