stride3d/stride · error · FontNotFoundException

Font file not found

Error message

Font file not found: {fontPath}

What it means

BitmapImporter.Import attempts to load the font source bitmap with Image.Load<Rgba32>; any failure (missing file or unreadable image) is converted into a FontNotFoundException carrying the resolved font path. This is the bitmap (offline-rasterized, image-based) font import path.

Solutions

  1. Check File.Exists(options.FontSource.GetFontPath()) and correct the FontSource path in the sprite font asset.
  2. Re-add the font bitmap to the asset project so the path resolves again.
  3. Validate the bitmap opens in an image viewer; re-export it if corrupt.

Example fix

// before
fontSource = "old/fonts/mybitmap.png";

// after
fontSource = "assets/fonts/mybitmap.png"; // path verified to exist
Defensive patterns

Strategy: validation

Validate before calling

var path = options.FontSource.GetFontPath();
if (string.IsNullOrEmpty(path) || !File.Exists(path))
    throw new FileNotFoundException(path);

Try / catch

try { ImportBitmapFont(options); } catch (FontNotFoundException ex) { log.Error($"Fix FontSource path: {ex.FontPath}"); }

Prevention

When it happens

Trigger: SpriteFontAsset.FontSource points to a path that does not exist, or Image.Load throws for a corrupt/unsupported bitmap file.

Common situations: Moving assets between machines so relative paths break; deleting a source .png/.bmp while keeping the .sdfont asset; unsupported image format.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/f622ec0d22e5bf4f. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Assets/SpriteFont/Compiler/BitmapImporter.cs:117

        // Properties hold the imported font data.
        public IEnumerable<Glyph> Glyphs { get; private set; }

        public float LineSpacing { get; private set; }

        public float BaseLine { get { return 0; } }

        public void Import(SpriteFontAsset options, List<char> characters)
        {
            // Load the source bitmap.
            Image<Rgba32> bitmap;

            try
            {
                bitmap = Image.Load<Rgba32>(options.FontSource.GetFontPath());
            }
            catch
            {
                throw new FontNotFoundException(options.FontSource.GetFontPath());
            }

            // What characters are included in this font?
            int characterIndex = 0;
            char currentCharacter = '\0';

            // Split the source image into a list of individual glyphs.
            var glyphList = new List<Glyph>();

            Glyphs = glyphList;
            LineSpacing = 0;

            foreach (Rectangle rectangle in FindGlyphs(bitmap))
            {
                if (characterIndex < characters.Count)
                    currentCharacter = characters[characterIndex++];
                else
                    currentCharacter++;

View on GitHub (pinned to 96fad776d2)