SixLabors/ImageSharp · error · NotSupportedException

{errorMessage}

Error message

{errorMessage}

What it means

JpegThrowHelper.ThrowNotSupportedException wraps NotSupportedException for features the JPEG codec explicitly does not support (e.g. 12-bit or arithmetic-coded baselines, certain marker combinations). It is an internal helper so throw sites stay JIT-friendly (no string interpolation on the hot path).

Solutions

  1. Re-encode the source image to standard 8-bit baseline or progressive JPEG using an external tool (e.g. ImageMagick, IrfanView) before loading.
  2. Upgrade ImageSharp — support for more JPEG features is added over time; check the release notes for 12-bit/arithmetic support.
  3. Catch NotSupportedException and route the file to a fallback decoder that supports the feature.

Example fix

// before
using var image = Image.Load(stream); // throws on unsupported JPEG
// after
try
{
    using var image = Image.Load(stream);
}
catch (NotSupportedException)
{
    // fall back to external decoder or reject the file
}
Defensive patterns

Strategy: try-catch

Validate before calling

// No pre-check API; sniff capability only by reading SOF precision from the file header bytes.

Try / catch

try
{
    using var image = Image.Load(stream);
}
catch (NotSupportedException ex)
{
    // route to external decoder or reject: unsupported JPEG feature
}

Prevention

When it happens

Trigger: Decoding a JPEG stream whose features are outside the codec's supported subset — most commonly 12-bit quantization/precision or arithmetic entropy coding — via Image.Load/LoadAsync on a JpegDecoder.

Common situations: Processing images produced by medical/scientific (DICOM-adjacent) or high-bit-depth cameras exporting 12-bit JPEGs; legacy encoders using arithmetic coding; pipelines migrating from other decoders (libjpeg-turbo) that accepted these files.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs:8

// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.ImageSharp.Formats.Jpeg;

internal static class JpegThrowHelper
{
    public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage);

    public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);

    public static void ThrowBadMarker(string marker, int length) => throw new InvalidImageContentException($"Marker {marker} has bad length {length}.");

    public static void ThrowNotEnoughBytesForMarker(byte marker) => throw new InvalidImageContentException($"Input stream does not have enough bytes to parse declared contents of the {marker:X2} marker.");

    public static void ThrowBadQuantizationTableIndex(int index) => throw new InvalidImageContentException($"Bad Quantization Table index {index}.");

    public static void ThrowBadQuantizationTablePrecision(int precision) => throw new InvalidImageContentException($"Unknown Quantization Table precision {precision}.");

    public static void ThrowBadSampling() => throw new InvalidImageContentException("Bad sampling factor.");

    public static void ThrowBadSampling(int factor) => throw new InvalidImageContentException($"Bad sampling factor: {factor}");

    public static void ThrowBadProgressiveScan(int ss, int se, int ah, int al) => throw new InvalidImageContentException($"Invalid progressive parameters Ss={ss} Se={se} Ah={ah} Al={al}.");

    public static void ThrowInvalidImageDimensions(int width, int height) => throw new InvalidImageContentException($"Invalid image dimensions: {width}x{height}.");

View on GitHub (pinned to 59ce6af6fc)