{"record":{"id":"6b64cab1fc4ec281","repo":"dotnet/wpf","slug":"sr-parsers-illegaltoken-parserscommon","errorCode":null,"errorMessage":"SR.Parsers_IllegalToken","messagePattern":"SR\\.Parsers_IllegalToken","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ParsersCommon.cs","lineNumber":138,"sourceCode":"                    {\n                        // If so, we only care if the first non-WhiteSpace char encountered is 'F'\n                        if (pathString[curIndex] == 'F')\n                        {\n                            curIndex++;\n\n                            // Since we found 'F' the next non-WhiteSpace char must be 0 or 1 - look for it.\n                            while ((curIndex < pathString.Length) && Char.IsWhiteSpace(pathString, curIndex))\n                            {\n                                curIndex++;\n                            }\n\n                            // If we ran out of text, this is an error, because 'F' cannot be specified without 0 or 1\n                            // Also, if the next token isn't 0 or 1, this too is illegal\n                            if ((curIndex == pathString.Length) ||\n                                ((pathString[curIndex] != '0') &&\n                                 (pathString[curIndex] != '1')))\n                            {\n                                throw new FormatException(SR.Parsers_IllegalToken);\n                            }\n                            \n#if PRESENTATION_CORE\n                            fillRule = pathString[curIndex] == '0' ? FillRule.EvenOdd : FillRule.Nonzero;\n#else\n                            fillRule = pathString[curIndex] != '0' ; \n\n#endif\n\n                            // Increment curIndex to point to the next char\n                            curIndex++;\n                        }\n                    }\n\n                    AbbreviatedGeometryParser parser = new AbbreviatedGeometryParser();\n            \n                    parser.ParseToGeometryContext(context, pathString, curIndex);\n                }","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ParsersCommon.cs#L120-L156","documentation":"The path mini-language parser reads an optional fill-rule flag 'F0' (EvenOdd) or 'F1' (Nonzero) at the start of a Path geometry string. If the input ends immediately after 'F' or the next character is not '0' or '1', FormatException(SR.Parsers_IllegalToken) is thrown: a fill-rule flag was specified without its required 0/1 digit.","triggerScenarios":"Parsing a Data/path string like 'Data=\"F M0,0 L10,10\"' (F with no digit) or 'Data=\"F2 M0,0 ...\"' (invalid flag value) via StreamGeometry.Parse, Geometry.Parse, or Path.Data in XAML.","commonSituations":"Hand-edited XAML Path.Data strings where the digit after F was deleted; geometry strings generated by tooling that emitted a bare 'F'; copy-pasted SVG path data adapted incorrectly to WPF syntax.","solutions":["Append the required digit: use 'F0' for EvenOdd or 'F1' for Nonzero before the path commands, or remove the 'F' flag entirely to use the default fill rule.","Fix generated geometry-string code so 'F' is never emitted without 0 or 1.","Validate the path string (e.g. regex check that F is followed by [01]) before calling Geometry.Parse.","Catch FormatException around parsing and fall back to a placeholder geometry."],"exampleFix":"// before\ngeometry = StreamGeometry.Parse(\"F M0,0 L10,10\"); // F without digit -> throws\n\n// after\ngeometry = StreamGeometry.Parse(\"F0 M0,0 L10,10\"); // F0 = EvenOdd (or drop the F flag)","handlingStrategy":"validation","validationCode":"static bool HasValidFillRuleFlag(string path)\n{\n    int i = path != null ? path.IndexOf('F') : -1;\n    return i < 0 || (i + 1 < path.Length && (path[i + 1] == '0' || path[i + 1] == '1'));\n}","typeGuard":null,"tryCatchPattern":"try { return StreamGeometry.Parse(data); }\ncatch (FormatException ex) { log.Warn(ex, \"Bad fill-rule flag in: \" + data); return new StreamGeometry(); }","preventionTips":["Always emit 'F0' or 'F1' together, or omit the F flag entirely.","Add regex check (^F[01]) for generated geometry strings.","When converting SVG paths to WPF, strip or complete partial fill-rule flags."],"tags":["wpf","path-geometry","streamgeometry","format-exception"],"backgroundTag":"invalid-argument-format","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"}