AvaloniaUI/Avalonia · error · InvalidOperationException

Could not load the '{TableName}' table.

Error message

Could not load the '{TableName}' table.

What it means

The 'maxp' table declares maximum values (glyph count, stack depth, instruction storage) the rasterizer uses to size buffers. MaxpTable.Load calls PlatformTypeface.TryGetTable(Tag, out ...) and throws when TryGetTable returns false, meaning the table directory has no 'maxp' entry. Fonts without maxp are unusable for layout.

Source

Thrown at src/Avalonia.Base/Media/Fonts/Tables/MaxpTable.cs:64

            MaxContours = maxContours;
            MaxCompositePoints = maxCompositePoints;
            MaxCompositeContours = maxCompositeContours;
            MaxZones = maxZones;
            MaxTwilightPoints = maxTwilightPoints;
            MaxStorage = maxStorage;
            MaxFunctionDefs = maxFunctionDefs;
            MaxInstructionDefs = maxInstructionDefs;
            MaxStackElements = maxStackElements;
            MaxSizeOfInstructions = maxSizeOfInstructions;
            MaxComponentElements = maxComponentElements;
            MaxComponentDepth = maxComponentDepth;
        }

        public static MaxpTable Load(GlyphTypeface fontFace)
        {
            if (!fontFace.PlatformTypeface.TryGetTable(Tag, out var table))
            {
                throw new InvalidOperationException($"Could not load the '{TableName}' table.");
            }

            var binaryReader = new BigEndianBinaryReader(table.Span);

            return Load(ref binaryReader);
        }

        private static MaxpTable Load(ref BigEndianBinaryReader reader)
        {
            // Version 0.5 (CFF/CFF2 fonts):
            // | Version16Dot16 | version   | 0x00005000 for version 0.5      |
            // | uint16         | numGlyphs | The number of glyphs in the font|
            
            // Version 1.0 (TrueType fonts):
            // | Version16Dot16 | version                | 0x00010000 for version 1.0                          |
            // | uint16         | numGlyphs              | The number of glyphs in the font                    |
            // | uint16         | maxPoints              | Maximum points in a non-composite glyph             |
            // | uint16         | maxContours            | Maximum contours in a non-composite glyph           |

View on GitHub (pinned to 11c5427268)

Solutions

  1. Run 'ttx -l font.ttf' (or fc-scan) on the asset and confirm 'maxp' is listed with a non-zero length.
  2. Re-fetch or re-export the font from a trusted source; a missing required table indicates corruption.
  3. If loading from a stream, verify the stream Length matches the file size on disk before handing it to GlyphTypeface.
  4. Guard untrusted font assets with a try/catch on InvalidOperationException around GlyphTypeface construction and fall back to a system font.

Example fix

// before
using var gt = new GlyphTypeface(stream);

// after
GlyphTypeface gt;
try { gt = new GlyphTypeface(stream); }
catch (InvalidOperationException ex) when (ex.Message.Contains("'maxp'"))
{
    _logger.LogError("Font asset missing maxp table (corrupt?): {Msg}", ex.Message);
    throw new InvalidDataException($"Font asset is corrupt or incomplete: missing 'maxp' table.", ex);
}
Defensive patterns

Strategy: validation

Validate before calling

static bool HasRequiredTables(string path)
{
    try { using var fs = File.OpenRead(path); using var r = new BinaryReader(fs);
        r.ReadUInt32(); r.ReadUInt16(); var n = r.ReadUInt16();
        var tags = new HashSet<string>();
        for (int i = 0; i < n; i++) { fs.Position = 12 + i*16; tags.Add(new string(r.ReadChars(4))); }
        return tags.Contains("maxp");
    } catch { return false; }
}

Try / catch

try { _gt = new GlyphTypeface(stream); }
catch (InvalidOperationException ex) when (ex.Message.Contains("'maxp'"))
{ throw new InvalidDataException($"Font asset is corrupt: {ex.Message}", ex); }

Prevention

When it happens

Trigger: Constructing a GlyphTypeface over a font stream/buffer where the sfnt table directory omits 'maxp'; loading a WOFF/WOFF2 whose deobfuscation produced a truncated sfnt; loading a TTC collection whose selected face index points at a face missing maxp.

Common situations: A binary-truncated download of a web font where the table directory survived but table data did not; an in-progress or hand-assembled font file (fontTools build gone wrong); reading a CFF2 OTF variant produced by an older toolchain that omitted maxp version 0.5.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/9b6accc4bf2d63d0. Report an issue: GitHub.