dotnet/wpf · error · ArgumentException
SR.GlyphTypefaceNotRecorded
Error message
SR.GlyphTypefaceNotRecorded
What it means
FontEmbeddingManager.GetUsedGlyphs throws this ArgumentException when the supplied glyphTypeface Uri was never recorded by a previous CollectGlyphTypefaces/embedding pass, so _collectedGlyphTypefaces contains no entry (or the stored entry is null). The method can only report glyphs for typefaces the manager has actually collected.
Solutions
- Ensure the glyph typefaces were collected first (render/layout text through the manager) before calling GetUsedGlyphs.
- Use the exact same glyphTypeface Uri that was recorded during collection.
- Check the Uri equals the keys recorded (scheme/casing differences produce different dictionary keys).
Example fix
// before var mgr = new FontEmbeddingManager(); var glyphs = mgr.GetUsedGlyphs(fontUri); // never recorded // after var mgr = new FontEmbeddingManager(); mgr.CollectGlyphTypefaces(textSource...); // run collection var glyphs = mgr.GetUsedGlyphs(fontUri);
Defensive patterns
Strategy: validation
Validate before calling
if (fontUri == null) throw new ArgumentNullException(nameof(fontUri)); // ensure collection happened; only query Uris produced by/used during collection
Try / catch
try { var glyphs = manager.GetUsedGlyphs(fontUri); }
catch (ArgumentException) { /* glyphTypeface was never recorded; run collection first */ } Prevention
- Run the glyph collection pass before querying GetUsedGlyphs.
- Keep and reuse the exact Uri instances that were collected.
- Normalize Uris (scheme, casing, trailing slash) before both collecting and querying.
When it happens
Trigger: Calling GetUsedGlyphs(uri) with a Uri that was never passed to the manager's glyph-collection step (e.g. different Uri instance/equality, or GetUsedGlyphs called before any text layout occurred).
Common situations: Embedding workflows where the developer constructs a fresh FontEmbeddingManager and asks for used glyphs without first running the collection that populates the dictionary, or querying a font Uri that differs from the one actually used at render time.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- SR.Collection_BadRank
- SR.FamilyMap_TargetNotSet
- SR.Format(SR.General_Expected_Type, "FontFamily")
- SR.Format(SR.PropertyValueCannotBeNaN, propertyName)
- SR.UriNotAbsolute
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/775a22eee1cb55ea.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontEmbeddingManager.cs:87
return _collectedGlyphTypefaces.Keys;
}
}
/// <summary>
/// Obtain the list of glyphs used by the glyph typeface specified by a Uri.
/// </summary>
/// <param name="glyphTypeface">Specifies the Uri of a glyph typeface to obtain usage data for.</param>
/// <returns>A collection of glyph indices recorded previously.</returns>
/// <exception cref="System.ArgumentException">
/// Glyph typeface Uri does not point to a previously recorded glyph typeface.
/// </exception>
[CLSCompliant(false)]
public ICollection<ushort> GetUsedGlyphs(Uri glyphTypeface)
{
Dictionary<ushort, bool> glyphsUsed = _collectedGlyphTypefaces[glyphTypeface];
if (glyphsUsed == null)
{
throw new ArgumentException(SR.GlyphTypefaceNotRecorded, nameof(glyphTypeface));
}
return glyphsUsed.Keys;
}
#endregion Public Methods
private class UriComparer : IEqualityComparer<Uri>
{
#region IEqualityComparer<Uri> Members
public bool Equals(Uri x, Uri y)
{
// We don't use Uri.Equals because it doesn't compare Fragment parts,
// and we use Fragment part to store font face index.
return String.Equals(x.ToString(), y.ToString(), StringComparison.OrdinalIgnoreCase);
}
public int GetHashCode(Uri obj)View on GitHub (pinned to 81131a70a4)