{"record":{"id":"7ada05588f8c39cc","repo":"dotnet/wpf","slug":"sr-glyphsindexrequiredifnounicode","errorCode":null,"errorMessage":"SR.GlyphsIndexRequiredIfNoUnicode","messagePattern":"SR\\.GlyphsIndexRequiredIfNoUnicode","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs","lineNumber":566,"sourceCode":"\n                        ReadOnlySpan<char> valueSpec = glyphsProp.AsSpan(valueStartIndex, len);\n\n                        #region Interpret one comma-delimited value\n\n                        switch (valueWithinGlyph)\n                        {\n                            case 0:\n                                bool wasInCluster = inCluster;\n                                // interpret cluster size and glyph index spec\n                                if (!ReadGlyphIndex(\n                                    valueSpec,\n                                    ref inCluster,\n                                    ref glyphClusterSize,\n                                    ref characterClusterSize,\n                                    ref parsedGlyphData.glyphIndex))\n                                {\n                                    if (String.IsNullOrEmpty(unicodeString))\n                                        throw new ArgumentException(SR.GlyphsIndexRequiredIfNoUnicode);\n\n                                    if (unicodeString.Length <= parsedCharacterCount)\n                                        throw new ArgumentException(SR.GlyphsUnicodeStringIsTooShort);\n\n                                    parsedGlyphData.glyphIndex = GetGlyphFromCharacter(fontFace, unicodeString[parsedCharacterCount]);\n                                }\n\n                                if (!wasInCluster && clusterMap != null)\n                                {\n                                    // fill out cluster map at the start of each cluster\n                                    if (inCluster)\n                                    {\n                                        for (int ch = parsedCharacterCount; ch < parsedCharacterCount + characterClusterSize; ++ch)\n                                        {\n                                            SetClusterMapEntry(clusterMap, ch, (ushort)parsedGlyphCount);\n                                        }\n                                    }\n                                    else","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs#L548-L584","documentation":"Thrown by Glyphs.ParseGlyphsProperty while filling glyph defaults with a 1:1 character-to-glyph mapping. When no explicit glyph index was parsed for a character, the code derives the glyph from the corresponding UnicodeString character — but if UnicodeString is null or empty there is nothing to derive from. The parser requires either explicit glyph indices or a non-empty UnicodeString.","triggerScenarios":"Assigning Glyphs.GlyphIndices (or UnicodeString) such that some positions lack explicit indices while Glyphs.UnicodeString is null or empty — e.g. GlyphIndices=\"\" with trailing ';' items, or Indices-only usage without setting UnicodeString/Characters.","commonSituations":"XAML Glyphs element that sets only GlyphIndices and forgets UnicodeString; data-bound or computed Indices strings that end with separators producing empty value slots.","solutions":["Set Glyphs.UnicodeString (or Characters) to a non-empty string when GlyphIndices omits any explicit glyph index.","Provide an explicit glyph index for every comma-separated slot in GlyphIndices.","Remove trailing/empty ';,' slots from the GlyphIndices string."],"exampleFix":"<!-- before -->\n<Glyphs GlyphIndices=\";15;20\" />\n<!-- after -->\n<Glyphs GlyphIndices=\";15;20\" UnicodeString=\"abc\" />","handlingStrategy":"validation","validationCode":"bool hasEmptySlotsNeedingUnicode = glyphIndices.Split(';').Any(string.IsNullOrEmpty);\nif (hasEmptySlotsNeedingUnicode && string.IsNullOrEmpty(glyphs.UnicodeString))\n    throw new InvalidOperationException(\"UnicodeString required when GlyphIndices omits explicit indices\");","typeGuard":"static bool IndicesSelfContained(string indices) => indices.Split(';').Where(s => s.Length > 0).Count() == indices.Split(';').Count(s => s.Length == 0) ? false : true; // empty slots exist -> UnicodeString needed\n// simpler: static bool NeedsUnicodeString(string indices) => indices != null && (indices.StartsWith(\";\") || indices.Contains(\";;\") || indices.EndsWith(\";\"));","tryCatchPattern":"try { glyphs.GlyphIndices = indices; }\ncatch (ArgumentException ex) when (string.IsNullOrEmpty(glyphs.UnicodeString)) { glyphs.UnicodeString = fallbackText; glyphs.GlyphIndices = indices; }","preventionTips":["Set UnicodeString before GlyphIndices when using empty index slots","Provide explicit indices for every glyph instead of empty slots","Validate XAML Glyphs elements with a linter that flags Indices without UnicodeString"],"tags":["wpf","glyphs","parsing","xaml","argumentexception"],"backgroundTag":"missing-required-argument","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"}