{"record":{"id":"c37b5505c22c68ee","repo":"AvaloniaUI/Avalonia","slug":"unexpected-path-command-c","errorCode":null,"errorMessage":"Unexpected path command '{c}'.","messagePattern":"Unexpected path command '(.+?)'\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/PathMarkupParser.cs","lineNumber":603,"sourceCode":"            var x = ReadDouble(ref span);\n            span = ReadSeparator(span);\n            var y = ReadDouble(ref span);\n            return new Point(origin.X + x, origin.Y + y);\n        }\n\n        private static bool ReadCommand(ref ReadOnlySpan<char> span, out Command command, out bool relative)\n        {\n            span = SkipWhitespace(span);\n            if (span.IsEmpty)\n            {\n                command = default;\n                relative = false;\n                return false;\n            }\n            var c = span[0];\n            if (!s_commands.TryGetValue(char.ToUpperInvariant(c), out command))\n            {\n                throw new InvalidDataException(\"Unexpected path command '\" + c + \"'.\");\n            }\n            relative = char.IsLower(c);\n            span = span.Slice(1);\n            return true;\n        }\n\n        [MemberNotNull(nameof(_geometryContext))]\n        private void ThrowIfDisposed()\n        {\n            if (_isDisposed || _geometryContext is null)\n                throw new ObjectDisposedException(nameof(PathMarkupParser));\n        }\n    }\n}\n","sourceCodeStart":585,"sourceCodeEnd":618,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/PathMarkupParser.cs#L585-L618","documentation":"Thrown by ReadCommand when the next non-whitespace character is not a recognized path command letter. The s_commands table accepts only F, M, L, H, V, Q, T, C, S, A, Z (case-insensitive — lower-case means relative). Any other character as a command position triggers this.","triggerScenarios":"Path strings with a stray character where a command letter is expected, e.g. 'M0,0 X10,10' (X is not a command), 'M0,0 l10 10b5,5' (b is not a command), or a leading punctuation mark.","commonSituations":"Typos in hand-written path data; mixing in SVG elements/attributes instead of the path 'd' grammar; stray text concatenated onto the data string; case where a number runs into where a command was expected after a malformed token.","solutions":["Use only the supported command letters (F M L H V Q T C S A Z); lower-case variants are relative.","Check the character reported in the message — it pinpoints the offending token.","Strip non-path text (XML attributes, namespaces) before passing the string to Parse()."],"exampleFix":"// before\ngeometry.Parse(\"M0,0 X10,10\");\n\n// after\ngeometry.Parse(\"M0,0 L10,10\");","handlingStrategy":"validation","validationCode":"static readonly HashSet<char> ValidCommands = new(\"FMLHVQTCSAZ\");\nstatic bool IsKnownCommand(char c) => ValidCommands.Contains(char.ToUpperInvariant(c));","typeGuard":"static bool IsKnownCommand(char c) => \"FMLHVQTCSAZ\".Contains(char.ToUpperInvariant(c));","tryCatchPattern":"try { parser.Parse(data); }\ncatch (InvalidDataException ex) when (ex.Message.StartsWith(\"Unexpected path command\"))\n{ /* report the offending character from the message */ }","preventionTips":["Whitelist command letters before parsing.","Use the message's quoted character to locate the bad token when debugging."],"tags":["avalonia","path-markup","command","invalid-data","parse"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}