dotnet/wpf · error · ArgumentException
SR.GlyphsCaretStopsContainsHexDigits
Error message
SR.GlyphsCaretStopsContainsHexDigits
What it means
Glyphs.ParseCaretStops validates the CaretStops string, which must contain only hex digits (0-9, a-f, A-F). Any other character makes the caret-stop bitmap unparseable, so an ArgumentException is thrown naming the CaretStops property.
Solutions
- Replace every non-hex character in the CaretStops string with a valid hex digit
- Remove separators/spaces between hex groups
- Validate the string with a regex before assigning it
Example fix
// before CaretStops = "00F0 0FF0"; // after CaretStops = "00F00FF0";
Defensive patterns
Strategy: validation
Validate before calling
bool ok = string.IsNullOrEmpty(caretStops) || System.Text.RegularExpressions.Regex.IsMatch(caretStops, "^[0-9a-fA-F]*$");
if (!ok) throw new ArgumentException("CaretStops must be hex digits only"); Try / catch
try { glyphs.CaretStops = value; } catch (ArgumentException) { /* sanitize to hex and retry */ } Prevention
- Regex-validate hex-only before assignment
- Never insert spaces/commas into CaretStops
- Build CaretStops with string.Format("{0:X}", bits) style code
When it happens
Trigger: Setting Glyphs.CaretStops (typically via XAML) to a string containing a non-hex character, e.g. spaces, 'g'-'z', punctuation, or sign characters.
Common situations: Hand-edited XAML where CaretStops was typo'd; programmatic string building that inserted separators like commas or spaces between hex groups.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- SR.GlyphsCaretStopsLengthCorrespondsToUnicodeString
- Collection_BadRank
- SR.GlyphsAdvanceWidthCannotBeNegative
- SR.GlyphsClusterBadCharactersBeforeBracket
- SR.GlyphsClusterMisplacedSeparator
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ea224566d992dd26.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs:248
bool[] caretStops = new bool[caretStopCount];
int i = 0;
foreach (char c in caretStopsString)
{
if (Char.IsWhiteSpace(c))
continue;
int nibble;
if ('0' <= c && c <= '9')
nibble = c - '0';
else if ('a' <= c && c <= 'f')
nibble = c - 'a' + 10;
else if ('A' <= c && c <= 'F')
nibble = c - 'A' + 10;
else
throw new ArgumentException(SR.GlyphsCaretStopsContainsHexDigits, "CaretStops");
Debug.Assert(0 <= nibble && nibble <= 15);
if ((nibble & 8) != 0)
{
if (i >= caretStops.Length)
throw new ArgumentException(SR.GlyphsCaretStopsLengthCorrespondsToUnicodeString, "CaretStops");
caretStops[i] = true;
}
++i;
if ((nibble & 4) != 0)
{
if (i >= caretStops.Length)
throw new ArgumentException(SR.GlyphsCaretStopsLengthCorrespondsToUnicodeString, "CaretStops");
caretStops[i] = true;
}
++i;
if ((nibble & 2) != 0)View on GitHub (pinned to 81131a70a4)