{"record":{"id":"d7309f5fe9fdf13b","repo":"dotnet/wpf","slug":"sr-streamgeometry-needbeginfigure","errorCode":null,"errorMessage":"SR.StreamGeometry_NeedBeginFigure","messagePattern":"SR\\.StreamGeometry_NeedBeginFigure","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ByteStreamGeometryContext.cs","lineNumber":203,"sourceCode":"\n            GenericPolyTo(points, \n                          isStroked, \n                          isSmoothJoin, \n                          hasCurves: true,\n                          pointCountMultiple: 3,\n                          MIL_SEGMENT_TYPE.MilSegmentPolyBezier);\n        }\n\n        /// <summary>\n        /// ArcTo - append an ArcTo to the current figure.\n        /// </summary>\n        public override void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, bool isStroked, bool isSmoothJoin)\n        {\n            VerifyApi();\n\n            if (_currentPathFigureDataOffset == -1)\n            {\n                throw new InvalidOperationException(SR.StreamGeometry_NeedBeginFigure);\n            }\n\n            FinishSegment();\n\n            MIL_SEGMENT_ARC arcToSegment = new MIL_SEGMENT_ARC\n            {\n                Type = MIL_SEGMENT_TYPE.MilSegmentArc\n            };\n\n            arcToSegment.Flags |= isStroked ? 0 : MILCoreSegFlags.SegIsAGap;\n            arcToSegment.Flags |= isSmoothJoin ? MILCoreSegFlags.SegSmoothJoin : 0;\n            arcToSegment.Flags |= MILCoreSegFlags.SegIsCurved;\n            arcToSegment.BackSize = _lastSegmentSize;\n\n            arcToSegment.Point = point;\n            arcToSegment.Size = size;\n            arcToSegment.XRotation = rotationAngle;\n            arcToSegment.LargeArc = (uint)(isLargeArc ? 1 : 0);","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ByteStreamGeometryContext.cs#L185-L221","documentation":"ByteStreamGeometryContext.ArcTo appends an arc segment to the current figure of a StreamGeometry. A segment can only be added after BeginFigure has been called; if no figure is open (_currentPathFigureDataOffset == -1) the context throws InvalidOperationException.","triggerScenarios":"Calling ArcTo on a StreamGeometryContext obtained from StreamGeometry.Open() before calling BeginFigure, or after the current figure was invalidated (e.g. after Dispose of prior state).","commonSituations":"Building path geometry programmatically where an arc is the first command; converting path data where the leading 'M' (move) command was dropped or skipped during parsing.","solutions":["Call context.BeginFigure(startPoint, isFilled, isClosed) before the first ArcTo.","Check the path-conversion/parsing code so a leading Move command is emitted as BeginFigure.","Guard each geometry-building routine so segments are only emitted when a figure is open."],"exampleFix":"// before\nusing (var ctx = geometry.Open())\n{\n    ctx.ArcTo(pt, size, 0, false, SweepDirection.Clockwise, true, false);\n}\n\n// after\nusing (var ctx = geometry.Open())\n{\n    ctx.BeginFigure(startPoint, true, false);\n    ctx.ArcTo(pt, size, 0, false, SweepDirection.Clockwise, true, false);\n}","handlingStrategy":"validation","validationCode":"bool figureOpen = ctx.GetType().GetProperty(\"CurrentFigureOpen\")?.GetValue(ctx) as bool? ?? true; if (!figureOpen) ctx.BeginFigure(startPoint, true, false);","typeGuard":null,"tryCatchPattern":"try { ctx.ArcTo(p, s, 0, false, SweepDirection.Clockwise, true, false); }\ncatch (InvalidOperationException) { ctx.BeginFigure(start, true, false); ctx.ArcTo(p, s, 0, false, SweepDirection.Clockwise, true, false); }","preventionTips":["Always emit BeginFigure as the first operation after StreamGeometry.Open().","In path parsers, map every leading Move command to BeginFigure and treat segments without a figure as parser bugs.","Encapsulate geometry building in a helper that tracks figure state."],"tags":["wpf","geometry","invalid-operation"],"backgroundTag":"invalid-state-transition","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"}