{"record":{"id":"a2019f436439ba16","repo":"AvaloniaUI/Avalonia","slug":"geometrycontext","errorCode":null,"errorMessage":"geometryContext","messagePattern":"geometryContext","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/PathMarkupParser.cs","lineNumber":47,"sourceCode":"                };\n\n        private IGeometryContext? _geometryContext;\n        private Point _currentPoint;\n        private Point? _beginFigurePoint;\n        private Point? _previousControlPoint;\n        private bool _isOpen;\n        private bool _isDisposed;\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"PathMarkupParser\"/> class.\n        /// </summary>\n        /// <param name=\"geometryContext\">The geometry context.</param>\n        /// <exception cref=\"ArgumentNullException\">geometryContext</exception>\n        public PathMarkupParser(IGeometryContext geometryContext)\n        {\n            if (geometryContext == null)\n            {\n                throw new ArgumentNullException(nameof(geometryContext));\n            }\n\n            _geometryContext = geometryContext;\n        }\n\n        private enum Command\n        {\n            None,\n            FillRule,\n            Move,\n            Line,\n            HorizontalLine,\n            VerticalLine,\n            CubicBezierCurve,\n            QuadraticBezierCurve,\n            SmoothCubicBezierCurve,\n            SmoothQuadraticBezierCurve,\n            Arc,","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/PathMarkupParser.cs#L29-L65","documentation":"Thrown by the PathMarkupParser constructor when the IGeometryContext argument is null. The parser is a writer: it parses a path markup string and emits BeginFigure/LineTo/BezierTo/etc. calls into the supplied IGeometryContext, so it cannot operate without a valid sink.","triggerScenarios":"Constructing the parser with a null context: new PathMarkupParser(null). Also happens when the variable holding the context was never assigned (e.g. a field left null, or a StreamGeometry.Open() result captured before the geometry was opened).","commonSituations":"Passing an unopened or disposed StreamGeometry's context, or wiring PathMarkupParser against a field that is conditionally initialized and happened to be null on this code path. Common when refactoring geometry creation or sharing a context across parsers.","solutions":["Pass a non-null IGeometryContext, typically obtained via ((StreamGeometry)geometry).Open() or StreamGeometryContext from a PathGeometry.","Guard the call site: if (context is not null) { using var p = new PathMarkupParser(context); p.Parse(data); }","If the context comes from a factory/field, ensure it is assigned before parser construction and never set back to null."],"exampleFix":"// before\nvar parser = new PathMarkupParser(null);\nparser.Parse(\"M0,0 L10,10\");\n\n// after\nvar sg = new StreamGeometry();\nusing (var ctx = sg.Open())\nusing (var parser = new PathMarkupParser(ctx))\n{\n    parser.Parse(\"M0,0 L10,10\");\n}","handlingStrategy":"validation","validationCode":"if (geometryContext is null)\n    throw new ArgumentNullException(nameof(geometryContext));\nvar parser = new PathMarkupParser(geometryContext);","typeGuard":"static bool IsValidContext(IGeometryContext? c) => c is not null;","tryCatchPattern":null,"preventionTips":["Obtain the context from StreamGeometry.Open() in the same scope that constructs the parser.","Treat a null context as a programming error at the call site rather than catching it downstream."],"tags":["avalonia","path-markup","null-argument","constructor","geometry"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}