{"record":{"id":"e7d132e1903ebf78","repo":"dotnet/wpf","slug":"sr-glyphscaretstopslengthcorrespondstounicodestring","errorCode":null,"errorMessage":"SR.GlyphsCaretStopsLengthCorrespondsToUnicodeString","messagePattern":"SR\\.GlyphsCaretStopsLengthCorrespondsToUnicodeString","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs","lineNumber":255,"sourceCode":"                    continue;\n\n                int nibble;\n\n                if ('0' <= c && c <= '9')\n                    nibble = c - '0';\n                else if ('a' <= c && c <= 'f')\n                    nibble = c - 'a' + 10;\n                else if ('A' <= c && c <= 'F')\n                    nibble = c - 'A' + 10;\n                else\n                    throw new ArgumentException(SR.GlyphsCaretStopsContainsHexDigits, \"CaretStops\");\n\n                Debug.Assert(0 <= nibble && nibble <= 15);\n\n                if ((nibble & 8) != 0)\n                {\n                    if (i >= caretStops.Length)\n                        throw new ArgumentException(SR.GlyphsCaretStopsLengthCorrespondsToUnicodeString, \"CaretStops\");\n                    caretStops[i] = true;\n                }\n                ++i;\n                if ((nibble & 4) != 0)\n                {\n                    if (i >= caretStops.Length)\n                        throw new ArgumentException(SR.GlyphsCaretStopsLengthCorrespondsToUnicodeString, \"CaretStops\");\n                    caretStops[i] = true;\n                }\n                ++i;\n                if ((nibble & 2) != 0)\n                {\n                    if (i >= caretStops.Length)\n                        throw new ArgumentException(SR.GlyphsCaretStopsLengthCorrespondsToUnicodeString, \"CaretStops\");\n                    caretStops[i] = true;\n                }\n                ++i;\n                if ((nibble & 1) != 0)","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs#L237-L273","documentation":"ParseCaretStops walks the hex digit string four caret stops per nibble; when a set bit indicates a caret stop for a code point index beyond the UnicodeString length, the caret-stop spec is longer than allowed and this ArgumentException is thrown.","triggerScenarios":"CaretStops string whose decoded bit count exceeds the number of code points in Glyphs.UnicodeString — e.g. long CaretStops paired with a short UnicodeString.","commonSituations":"Changing UnicodeString to a shorter text but leaving the old CaretStops value in place in XAML; copying CaretStops between Glyphs elements with different string lengths.","solutions":["Shorten the CaretStops string so it covers at most the UnicodeString code-point count","Regenerate CaretStops from the current UnicodeString","If caret stops are not needed, clear CaretStops entirely"],"exampleFix":"// before\nUnicodeString=\"abc\" CaretStops=\"FFFFFFFF\"\n// after\nUnicodeString=\"abc\" CaretStops=\"F0\"","handlingStrategy":"validation","validationCode":"int codePoints = unicodeString.OfType<char>().Count(c => !char.IsSurrogate(c) || char.IsHighSurrogate(c));\nint maxBits = caretStops.Length * 4;\nbool ok = maxBits <= codePoints;","typeGuard":null,"tryCatchPattern":"try { glyphs.CaretStops = stops; } catch (ArgumentException) { /* regenerate stops from current string */ }","preventionTips":["Regenerate CaretStops whenever UnicodeString changes","Compare lengths in code points, not chars","Trim excess hex digits covering past-the-end stops"],"tags":["wpf","glyphs","xaml-parsing"],"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"}