{"record":{"id":"5d3a2cd55b584464","repo":"dotnet/wpf","slug":"sr-glyphsunicodestringandindicescannotbothbeempty","errorCode":null,"errorMessage":"SR.GlyphsUnicodeStringAndIndicesCannotBothBeEmpty","messagePattern":"SR\\.GlyphsUnicodeStringAndIndicesCannotBothBeEmpty","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs","lineNumber":300,"sourceCode":"            // If the number of entries in the caret stop specification string is less than the number of code points,\n            // set the remaining caret stop values to true.\n            while (i < caretStops.Length)\n            {\n                caretStops[i++] = true;\n            }\n            glyphRunProperties.caretStops = caretStops;\n        }\n\n        private void ParseGlyphRunProperties()\n        {\n            LayoutDependentGlyphRunProperties glyphRunProperties = null;\n            Uri uri = FontUri;\n\n            if (uri != null)\n            {\n                // Indices and UnicodeString cannot both be empty.\n                if (String.IsNullOrEmpty(UnicodeString) && String.IsNullOrEmpty(Indices))\n                    throw new ArgumentException(SR.GlyphsUnicodeStringAndIndicesCannotBothBeEmpty);\n\n                glyphRunProperties = new LayoutDependentGlyphRunProperties(GetDpi().PixelsPerDip);\n\n                if (!uri.IsAbsoluteUri)\n                {\n                    uri = BindUriHelper.GetResolvedUri(BaseUriHelper.GetBaseUri(this), uri);\n                }\n\n                // Package-boundary guard. When this Glyphs element is loaded\n                // inside an XPS package context, reject any FontUri that\n                // escapes the package. This ensures that font resources\n                // referenced within XPS documents remain contained within the\n                // same package, consistent with the XPS specification.\n                MS.Internal.XpsLoadingContext.EnforcePackageRelativeUri(BaseUriHelper.GetBaseUri(this), uri);\n                glyphRunProperties.glyphTypeface = new GlyphTypeface(uri, StyleSimulations);\n\n                glyphRunProperties.unicodeString = UnicodeString;\n                glyphRunProperties.sideways = IsSideways;","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Glyphs.cs#L282-L318","documentation":"When computing the GlyphRun for a Glyphs element, both UnicodeString and Indices being null or empty leaves nothing to render, so ParseGlyphRunProperties throws this ArgumentException during measure/layout.","triggerScenarios":"Creating a Glyphs element (in XAML or code) with neither UnicodeString nor Indices set, then measuring/rendering it; both properties set to empty strings.","commonSituations":"Data-bound Glyphs where the bound source returned an empty string; XAML templates where Glyphs properties are supplied later; default-constructed Glyphs added directly to a canvas.","solutions":["Set either UnicodeString or Indices to a non-empty value before the element is measured","If no glyphs are wanted, remove the Glyphs element instead of leaving both properties empty","Ensure data bindings produce non-empty values before layout"],"exampleFix":"// before\n<g:Glyphs FontUri=\"...\" OriginX=\"0\" OriginY=\"0\" />\n// after\n<g:Glyphs FontUri=\"...\" OriginX=\"0\" OriginY=\"0\" UnicodeString=\"Hello\" />","handlingStrategy":"validation","validationCode":"bool ok = !string.IsNullOrEmpty(glyphs.UnicodeString) || !string.IsNullOrEmpty(glyphs.Indices);\nif (!ok) { /* set one or remove the element */ }","typeGuard":null,"tryCatchPattern":"try { host.Measure(availableSize); } catch (ArgumentException) { /* Glyphs had no content; hide or populate */ }","preventionTips":["Set UnicodeString (or Indices) whenever constructing Glyphs","Guard data bindings with fallback values","Remove empty Glyphs elements instead of rendering them"],"tags":["wpf","glyphs","layout"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}