SixLabors/ImageSharp · error · NotSupportedException

Invalid interlace method. Expected 'None' or 'Adam7'. Was

Error message

Invalid interlace method. Expected 'None' or 'Adam7'. Was '{this.InterlaceMethod}'.

What it means

PngHeader.Validate throws this NotSupportedException when the IHDR interlace method is neither 0 (None) nor 1 (Adam7), the only two methods the PNG specification defines. The library cannot de-interlace an image that uses any other value.

Solutions

  1. Re-encode the PNG with a standard encoder that sets interlace to None or Adam7.
  2. Verify file integrity and re-download/re-export.
  3. Catch NotSupportedException around Image.Load and handle the invalid file (skip, log, or substitute).

Example fix

// before
using var image = Image.Load("broken.png");
// after
try
{
    using var image = Image.Load("broken.png");
}
catch (NotSupportedException ex)
{
    Console.WriteLine($"Non-conformant PNG header: {ex.Message}");
}
Defensive patterns

Strategy: try-catch

Validate before calling

// interlace method byte must be 0 (None) or 1 (Adam7)
static bool IsSupportedInterlace(byte interlaceMethod) => interlaceMethod is 0 or 1;

Type guard

static bool IsSupportedInterlace(byte m) => m is 0 or 1;

Try / catch

try
{
    using var image = Image.Load(pngStream);
}
catch (NotSupportedException ex) when (ex.Message.Contains("interlace method"))
{
    log.LogWarning("PNG rejected: {Msg}", ex.Message);
}

Prevention

When it happens

Trigger: Decoding a PNG whose IHDR InterlaceMethod byte is >= 2 — only possible via non-conformant encoders or corruption of the header bytes.

Common situations: Malformed or fuzzed PNG inputs, corrupted files, or files produced by experimental tooling using undefined interlace values.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/Formats/Png/Chunks/PngHeader.cs:109

        if (!PngConstants.ColorTypes.TryGetValue(this.ColorType, out byte[] supportedBitDepths))
        {
            throw new NotSupportedException($"Invalid or unsupported color type. Was '{this.ColorType}'.");
        }

        if (supportedBitDepths.AsSpan().IndexOf(this.BitDepth) == -1)
        {
            throw new NotSupportedException($"Invalid or unsupported bit depth. Was '{this.BitDepth}'.");
        }

        if (this.FilterMethod != 0)
        {
            throw new NotSupportedException($"Invalid filter method. Expected 0. Was '{this.FilterMethod}'.");
        }

        // The png specification only defines 'None' and 'Adam7' as interlaced methods.
        if (this.InterlaceMethod is not PngInterlaceMode.None and not PngInterlaceMode.Adam7)
        {
            throw new NotSupportedException($"Invalid interlace method. Expected 'None' or 'Adam7'. Was '{this.InterlaceMethod}'.");
        }
    }

    /// <summary>
    /// Writes the header to the given buffer.
    /// </summary>
    /// <param name="buffer">The buffer to write to.</param>
    public void WriteTo(Span<byte> buffer)
    {
        BinaryPrimitives.WriteInt32BigEndian(buffer[..4], this.Width);
        BinaryPrimitives.WriteInt32BigEndian(buffer.Slice(4, 4), this.Height);

        buffer[8] = this.BitDepth;
        buffer[9] = (byte)this.ColorType;
        buffer[10] = this.CompressionMethod;
        buffer[11] = this.FilterMethod;
        buffer[12] = (byte)this.InterlaceMethod;
    }

View on GitHub (pinned to 59ce6af6fc)