SixLabors/ImageSharp · error · InvalidImageContentException

The ANI file contains an unsupported frame format.

Error message

The ANI file contains an unsupported frame format.

What it means

Thrown by AniDecoderCore.Decode when an embedded ANI frame's format is not one of the supported decoders (Cur, Ico via CurDecoderCore, or raw Bmp via BmpDecoderCore with SkipFileHeader). Indicates the resolved AniFrameFormat fell outside the handled switch cases.

Solutions

  1. Ensure embedded frame resources are valid ICO, CUR, or BMP data by re-exporting the ANI.
  2. Inspect the embedded resource headers to confirm the format resolves to a supported type.
  3. Catch InvalidImageContentException and skip or reject the offending frame.
Defensive patterns

Strategy: try-catch

Try / catch

try { var image = await Image.LoadAsync(stream); } catch (InvalidImageContentException ex) { SkipFrameOrReject(ex); }

Prevention

When it happens

Trigger: Decoding an ANI file whose embedded frame resource resolves to an unhandled AniFrameFormat value during Decode.

Common situations: ANI files with malformed icon headers that map to an unexpected format, corrupted files, or future/unknown resource types written by other encoders.

Related errors


AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13). Data as JSON: /api/errors/6b339080b6564e30. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Formats/Ani/AniDecoderCore.cs:696

    /// </summary>
    /// <typeparam name="TPixel">The destination pixel type.</typeparam>
    /// <param name="format">The embedded resource format.</param>
    /// <param name="options">The nested decoder options.</param>
    /// <param name="stream">The bounded resource stream.</param>
    /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
    /// <returns>The decoded resource.</returns>
    private static Image<TPixel> DecodeFrame<TPixel>(AniFrameFormat format, DecoderOptions options, Stream stream, CancellationToken cancellationToken)
        where TPixel : unmanaged, IPixel<TPixel>
        => format switch
        {
            AniFrameFormat.Ico => new IcoDecoderCore(options).Decode<TPixel>(options.Configuration, stream, cancellationToken),
            AniFrameFormat.Cur => new CurDecoderCore(options).Decode<TPixel>(options.Configuration, stream, cancellationToken),
            AniFrameFormat.Bmp => new BmpDecoderCore(new BmpDecoderOptions
            {
                GeneralOptions = options,
                SkipFileHeader = true
            }).Decode<TPixel>(options.Configuration, stream, cancellationToken),
            _ => throw new InvalidImageContentException("The ANI file contains an unsupported frame format.")
        };

    /// <summary>
    /// Identifies one embedded ANI frame resource.
    /// </summary>
    /// <param name="format">The embedded resource format.</param>
    /// <param name="options">The nested decoder options.</param>
    /// <param name="stream">The bounded resource stream.</param>
    /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
    /// <returns>The identified resource.</returns>
    private static ImageInfo IdentifyFrame(AniFrameFormat format, DecoderOptions options, Stream stream, CancellationToken cancellationToken)
        => format switch
        {
            AniFrameFormat.Ico => new IcoDecoderCore(options).Identify(options.Configuration, stream, cancellationToken),
            AniFrameFormat.Cur => new CurDecoderCore(options).Identify(options.Configuration, stream, cancellationToken),
            AniFrameFormat.Bmp => new BmpDecoderCore(new BmpDecoderOptions
            {
                GeneralOptions = options,

View on GitHub (pinned to 59ce6af6fc)