stride3d/stride · error · ArgumentException
Tried to compile a dynamic sprite font with compiler for…
Error message
Tried to compile a dynamic sprite font with compiler for static fonts
What it means
OfflineRasterizedFontCompiler.Compile casts fontAsset.FontType to OfflineRasterizedSpriteFontType; if the cast returns null the asset uses a dynamic (runtime-rasterized) font type, which this static compiler cannot handle, so an ArgumentException is thrown.
Solutions
- Use the appropriate compiler for dynamic fonts (dynamic font factory/runtime path).
- Check fontAsset.FontType is OfflineRasterizedSpriteFontType before calling this compiler.
- Change the asset's font type to offline-rasterized if static compilation is intended.
Example fix
// before
OfflineRasterizedFontCompiler.Compile(factory, dynamicFontAsset, srgb);
// after
if (dynamicFontAsset.FontType is OfflineRasterizedSpriteFontType)
OfflineRasterizedFontCompiler.Compile(factory, dynamicFontAsset, srgb);
else
DynamicSpriteFontCompiler.Compile(factory, dynamicFontAsset, srgb); Defensive patterns
Strategy: type-guard
Type guard
bool CanCompileOffline(SpriteFontAsset asset) => asset.FontType is OfflineRasterizedSpriteFontType;
Try / catch
catch (ArgumentException ex) when (ex.Message.Contains("dynamic sprite font")) { /* route to dynamic compiler */ } Prevention
- Branch on FontType before selecting a compiler.
- Keep a single factory method that dispatches static vs dynamic fonts.
When it happens
Trigger: Calling OfflineRasterizedFontCompiler.Compile with a SpriteFontAsset whose FontType is a dynamic font type (e.g. DynamicSpriteFontType) instead of OfflineRasterizedSpriteFontType.
Common situations: Custom build pipelines that route all sprite fonts through the offline compiler without checking FontType; switching a font asset from static to dynamic and reusing old compile code.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Font does not contain any glyphs.
- Tried to compile a dynamic sprite font with compiler for…
- Tried to compile a dynamic sprite font with compiler for…
- Unsupported type for non-pointer indexer
- Unexpected arguments
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/31561de4a5b7775f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Assets/SpriteFont/Compiler/OfflineRasterizedFontCompiler.cs:108
namespace Stride.Assets.SpriteFont.Compiler
{
/// <summary>
/// Main class used to compile a Font file XML file.
/// </summary>
public class OfflineRasterizedFontCompiler
{
/// <summary>
/// Compiles the specified font description into a <see cref="OfflineRasterizedSpriteFont" /> object.
/// </summary>
/// <param name="fontFactory">The font factory used to create the fonts</param>
/// <param name="fontAsset">The font description.</param>
/// <param name="srgb"></param>
/// <returns>A SpriteFontData object.</returns>
public static Graphics.SpriteFont Compile(IFontFactory fontFactory, SpriteFontAsset fontAsset, bool srgb)
{
var fontTypeStatic = fontAsset.FontType as OfflineRasterizedSpriteFontType;
if (fontTypeStatic == null)
throw new ArgumentException("Tried to compile a dynamic sprite font with compiler for static fonts");
float lineSpacing;
float baseLine;
var glyphs = ImportFont(fontAsset, out lineSpacing, out baseLine);
// Optimize.
foreach (Glyph glyph in glyphs)
GlyphCropper.Crop(glyph);
Image<Rgba32> bitmap = GlyphPacker.ArrangeGlyphs(glyphs);
// Automatically detect whether this is a monochromatic or color font?
//if (fontAsset.Format == FontTextureFormat.Auto)
//{
// bool isMono = BitmapUtils.IsRgbEntirely(Color.White, bitmap);
//
// fontAsset.Format = isMono ? FontTextureFormat.CompressedMono :View on GitHub (pinned to 96fad776d2)