dotnet/wpf · error · ArgumentException

SR.GlyphsTooManyCommas

Error message

SR.GlyphsTooManyCommas

What it means

Thrown by Glyphs.ParseGlyphsProperty when a single glyph specification contains more comma-separated values than the parser understands. Each glyph slot accepts at most index, advance width, offset X, and offset Y (valueWithinGlyph 0..2 plus the index); anything beyond that hits the default case, which throws ArgumentException ("too many commas").

Solutions

  1. Remove extra comma-separated fields so each glyph has at most index, advanceWidth, offsetX, offsetY.
  2. Strip trailing/empty comma slots from each glyph spec.
  3. In generator code, format exactly the fields supported by Glyphs.GlyphIndices.

Example fix

// before
glyphs.GlyphIndices = ";41,10.5,0,0,7"; // 5 fields
// after
glyphs.GlyphIndices = ";41,10.5,0,0";   // max 4 fields
Defensive patterns

Strategy: validation

Validate before calling

static string FormatGlyphEntry(params double[] fields) { if (fields.Length > 4) throw new ArgumentException("Max 4 fields per glyph"); return ";" + string.Join(",", fields); }

Type guard

static bool FieldCountValid(string entry) => entry.Split(',').Length <= 4;

Try / catch

try { glyphs.GlyphIndices = indices; }
catch (ArgumentException ex) when (ex.Message.Contains("comma")) { indices = string.Join(";", indices.Split(';').Select(TrimToFourFields)); glyphs.GlyphIndices = indices; }

Prevention

When it happens

Trigger: A GlyphIndices string with extra trailing comma fields per glyph, e.g. ";41,10,0,0,5" or a stray double comma producing an extra empty value slot beyond the allowed count.

Common situations: Generator/exporter code emitting additional per-glyph metrics WPF doesn't accept; accidental trailing commas like ";41,10,,"; copy-paste from formats with more fields (e.g. font tool exports).

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/796c046102e85f71. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs:616

                                        throw new ArgumentException(SR.GlyphsAdvanceWidthCannotBeNegative);
                                }
                                break;

                            case 2:
                                // interpret glyph offset X
                                if (!IsEmpty(valueSpec))
                                    parsedGlyphData.offsetX = double.Parse(valueSpec, provider: CultureInfo.InvariantCulture);
                                break;

                            case 3:
                                // interpret glyph offset Y
                                if (!IsEmpty(valueSpec))
                                    parsedGlyphData.offsetY = double.Parse(valueSpec, provider: CultureInfo.InvariantCulture);
                                break;

                            default:
                                // too many commas; can't interpret
                                throw new ArgumentException(SR.GlyphsTooManyCommas);
                        }
                        #endregion Interpret one comma-delimited value

                        // prepare to scan next value (if any)
                        valueWithinGlyph++;
                        valueStartIndex = i + 1;
                    }

                    // finished processing the current glyph?
                    if ((c == ';') || (i == glyphsProp.Length))
                    {
                        parsedGlyphs.Add(parsedGlyphData);
                        parsedGlyphData = new ParsedGlyphData();

                        if (inCluster)
                        {
                            --glyphClusterSize;
                            // when we reach the end of a glyph cluster, increment character index

View on GitHub (pinned to 81131a70a4)