SixLabors/ImageSharp · error · NotSupportedException

Invalid or . . Was ' ' and ' '.

Error message

Invalid {name1} or {name2}. {message}. Was '{value1}' and '{value2}'.

What it means

The two-parameter overload of PngThrowHelper.ThrowInvalidParameter throws NotSupportedException reading 'Invalid {name1} or {name2}. {message}. Was {value1} and {value2}.' It is used when a combination of two decoded PNG chunk fields is jointly invalid even though either alone might be plausible. Like the single-value overload, the parameter names come from CallerArgumentExpression, so the message shows the exact decoded fields.

Solutions

  1. Read both values in the message and check the PNG's fcTL chunk geometry with a validator such as pngcheck -v.
  2. Re-encode the animation with a standards-compliant APNG encoder so frames fit within the declared canvas.
  3. Wrap decode in try/catch for NotSupportedException and surface a 'corrupt animation' error to end users.
  4. If you control generation of these files, add encoder-side assertions that xOffset + width <= canvas width.

Example fix

// before
using var image = Image.Load("broken.apng");
// after
try
{
    using var image = Image.Load("broken.apng");
}
catch (NotSupportedException ex)
{
    throw new InvalidDataException($"APNG frame geometry invalid: {ex.Message}", ex);
}
Defensive patterns

Strategy: try-catch

Try / catch

try { using var img = await Image.LoadAsync(stream); }
catch (NotSupportedException ex) { throw new InvalidDataException($"APNG frame geometry invalid: {ex.Message}", ex); }

Prevention

When it happens

Trigger: Decoding a PNG/APNG where two related frame-control fields are inconsistent — concretely FrameControl.XOffset + Width exceeding the main PngHeader.Width, checked at src/ImageSharp/Formats/Png/Chunks/FrameControl.cs:117.

Common situations: Malformed APNG frame geometry from broken encoders; corrupted or partially-written animation files; hand-edited binary PNG chunks; fuzzed test corpora.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/Formats/Png/PngThrowHelper.cs:47

    [DoesNotReturn]
    public static void ThrowMissingPalette() => throw new InvalidImageContentException("PNG Image does not contain a palette chunk.");

    [DoesNotReturn]
    public static void ThrowInvalidChunkType() => throw new InvalidImageContentException("Invalid PNG data.");

    [DoesNotReturn]
    public static void ThrowInvalidChunkType(string message) => throw new InvalidImageContentException(message);

    [DoesNotReturn]
    public static void ThrowInvalidChunkCrc(string chunkTypeName) => throw new InvalidImageContentException($"CRC Error. PNG {chunkTypeName} chunk is corrupt!");

    [DoesNotReturn]
    public static void ThrowInvalidParameter(object value, string message, [CallerArgumentExpression(nameof(value))] string name = "")
        => throw new NotSupportedException($"Invalid {name}. {message}. Was '{value}'.");

    [DoesNotReturn]
    public static void ThrowInvalidParameter(object value1, object value2, string message, [CallerArgumentExpression(nameof(value1))] string name1 = "", [CallerArgumentExpression(nameof(value2))] string name2 = "")
        => throw new NotSupportedException($"Invalid {name1} or {name2}. {message}. Was '{value1}' and '{value2}'.");

    [DoesNotReturn]
    public static void ThrowNotSupportedColor() => throw new NotSupportedException("Unsupported PNG color type.");

    [DoesNotReturn]
    public static void ThrowUnknownFilter() => throw new InvalidImageContentException("Unknown filter type.");
}

View on GitHub (pinned to 59ce6af6fc)