MonoGame/MonoGame · error · InvalidOperationException

The specified DefaultCharacter is not part of this font.

Error message

The specified DefaultCharacter is not part of this font.

What it means

Thrown by FontDescriptionProcessor.ImportFont as an InvalidOperationException when the DefaultCharacter specified in the FontDescription is not found among the glyphs produced by the font importer. The default character is used at runtime to substitute missing characters, so it must itself exist in the font.

Source

Thrown at MonoGame.Framework.Content.Pipeline/Processors/FontDescriptionProcessor.cs:229

            // Sort the glyphs
            glyphs.Sort((left, right) => left.Character.CompareTo(right.Character));


            // Check that the default character is part of the glyphs
            if (options.DefaultCharacter != null)
            {
                bool defaultCharacterFound = false;
                foreach (var glyph in glyphs)
                {
                    if (glyph.Character == options.DefaultCharacter)
                    {
                        defaultCharacterFound = true;
                        break;
                    }
                }
                if (!defaultCharacterFound)
                {
                    throw new InvalidOperationException("The specified DefaultCharacter is not part of this font.");
                }
            }

            return glyphs.ToArray();
        }

        private static string? FindFont(string name, string style)
        {
            if (CurrentPlatform.OS == OS.Windows)
            {
#pragma warning disable CA1416 // Validate platform compatibility
                var fontDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Fonts");
                foreach (var key in new[] { Registry.LocalMachine, Registry.CurrentUser })
                {
                    var subkey = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", false);
                    if (subkey == null)
                    {
                        return null;

View on GitHub (pinned to 1d71bbd0ff)

Solutions

  1. Set DefaultCharacter to a character that exists in the font (commonly a space, '?', or a box character).
  2. Remove the DefaultCharacter element from the .spritefont if you don't need fallback substitution.
  3. Switch to a font that includes the desired default character.

Example fix

// .spritefont
// before
<DefaultCharacter>&#x3000;</DefaultCharacter> // ideographic space not in font
// after
<DefaultCharacter>?</DefaultCharacter> // '?' exists in most fonts
Defensive patterns

Strategy: validation

Validate before calling

// Before building, check if DefaultCharacter is likely valid
// (basic range check — the font may still not have it)
if (fontDesc.DefaultCharacter.HasValue)
{
    var ch = fontDesc.DefaultCharacter.Value;
    if (ch < ' ' || ch > 0xFFFF)
        throw new InvalidOperationException($"DefaultCharacter '{ch}' is outside typical font range.");
}

Try / catch

try
{
    context.BuildAsset<FontDescription, SpriteFontContent>(fontDesc, processor);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("DefaultCharacter"))
{
    fontDesc.DefaultCharacter = null; // or set to '?'
    context.BuildAsset<FontDescription, SpriteFontContent>(fontDesc, processor);
}

Prevention

When it happens

Trigger: Setting DefaultCharacter in the .spritefont to a character code point that the font does not contain. For example, setting DefaultCharacter to a CJK character in a Latin-only font, or to a symbol not covered by the font's glyph set.

Common situations: The .spritefont's DefaultCharacter element specifies a Unicode character that doesn't exist in the chosen font. The font was changed but the DefaultCharacter was not updated. A custom character set excludes the default character.

Related errors


AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13). Data as JSON: /api/errors/c0d834e0ca5629b2. Report an issue: GitHub.