AvaloniaUI/Avalonia · error · InvalidOperationException
Could not create glyphTypeface. Font family: {FontFamily?.Na
Error message
Could not create glyphTypeface. Font family: {FontFamily?.Name} (key: {FontFamily?.Key}). Style: {Style}. Weight: {Weight}. Stretch: {Stretch} What it means
Thrown by the Typeface.GlyphTypeface getter when FontManager.Current.TryGetGlyphTypeface fails to resolve a matching glyph typeface for the given Typeface (family, style, weight, stretch). This is an InvalidOperationException indicating the font could not be loaded or matched at all. The message includes the family name/key and the requested style/weight/stretch for diagnostics.
Source
Thrown at src/Avalonia.Base/Media/Typeface.cs:95
/// </summary>
public FontStretch Stretch { get; }
/// <summary>
/// Gets the glyph typeface.
/// </summary>
/// <value>
/// The glyph typeface.
/// </value>
public GlyphTypeface GlyphTypeface
{
get
{
if(FontManager.Current.TryGetGlyphTypeface(this, out var glyphTypeface))
{
return glyphTypeface;
}
throw new InvalidOperationException(
$"Could not create glyphTypeface. Font family: {FontFamily?.Name} (key: {FontFamily?.Key}). Style: {Style}. Weight: {Weight}. Stretch: {Stretch}");
}
}
public static bool operator !=(Typeface a, Typeface b)
{
return !(a == b);
}
public static bool operator ==(Typeface a, Typeface b)
{
return a.Equals(b);
}
public override bool Equals(object? obj)
{
return obj is Typeface typeface && Equals(typeface);
}View on GitHub (pinned to 11c5427268)
Solutions
- Verify the FontFamily name exactly matches the font's internal family name (use a font inspection tool).
- Ensure custom fonts are included as assets and the FontFamily URI points to the correct resource path.
- Provide fallback fonts so FontManager can substitute when the primary is unavailable.
- On CI/headless environments, install the required system fonts or ship embedded font assets.
- For trimming/NativeAOT, ensure font resources are not trimmed and the font loader is rooted.
Example fix
// before
var tf = new Typeface(new FontFamily("MyCustomFont")); // not registered
var glyph = tf.GlyphTypeface; // throws
// after
var tf = new Typeface(new FontFamily("avares://MyApp/Assets/Fonts/#MyCustomFont"));
var glyph = tf.GlyphTypeface; Defensive patterns
Strategy: validation
Validate before calling
static bool CanResolveGlyphTypeface(Typeface tf)
=> FontManager.Current.TryGetGlyphTypeface(tf, out _); Try / catch
try { return tf.GlyphTypeface; }
catch (InvalidOperationException) { return fallbackTypeface.GlyphTypeface; } Prevention
- Register custom fonts as embedded assets with correct FontFamily URIs.
- Provide fallback font families for cross-platform/CI robustness.
- Install or embed required fonts in headless/CI environments.
- For NativeAOT, ensure font assets and loaders are not trimmed.
When it happens
Trigger: Accessing typeface.GlyphTypeface when the FontManager cannot find or load any font matching the specified FontFamily and attributes. Happens with a missing custom font asset, an unregistered font family, an embedded resource that failed to load, or a weight/stretch combination with no fallback.
Common situations: Bundling a custom font but forgetting to register it or mis-specifying its family name; referencing a system font not present on the target OS (common in CI/Linux containers); NativeAOT/trimming stripping the font asset; requesting an exotic weight/stretch the installed fonts do not cover.
Related errors
- Font weight must be > 0.
- Font stretch must be > 1.
- No cmap table found.
- glyphRun
- Duration value cannot be negative.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/5279c3a0d65eaed6.
Report an issue: GitHub.