SixLabors/ImageSharp · error · InvalidImageContentException

Could not find any converter for JpegColorSpace

Error message

Could not find any converter for JpegColorSpace {colorSpace}!

What it means

JpegColorConverterBase.GetConverter looks up a color converter matching both the JPEG color space and the decoder precision; if none exists it throws InvalidImageContentException. The bitstream declares a color space/precision combination the library has no conversion implementation for.

Solutions

  1. Re-encode the JPEG to a standard 8-bit YCbCr or RGB colorspace with another tool before loading
  2. Catch InvalidImageContentException and reject/convert the file at intake
  3. Upgrade ImageSharp — new versions add converters for additional color spaces and precisions
  4. Verify the file isn't corrupt: a malformed SOF can imply a bogus color space

Example fix

// before
using var image = Image.Load(oddJpegStream); // InvalidImageContentException
// after
try { using var image = Image.Load(oddJpegStream); }
catch (InvalidImageContentException)
{
    // Convert with e.g. ImageMagick/skia to baseline YCbCr, then retry
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Reject non-8-bit JPEGs before decoding
if (IsTwelveBitJpeg(stream)) throw new UnsupportedFormatException("12-bit JPEG not supported.");

Try / catch

try { using var image = Image.Load(jpegStream); }
catch (InvalidImageContentException ex) when (ex.Message.Contains("converter"))
{
    // colorspace/precision combination unsupported
    return TranscodeWithExternalTool();
}

Prevention

When it happens

Trigger: Decoding a JPEG whose frame indicates a JpegColorSpace (e.g. unusual YCCK/CMYK or Adobe-transform variants) combined with a precision (8 or 12 bit) for which no registered converter exists in JpegColorConverterBase.Converters.

Common situations: 12-bit or 16-bit precision JPEGs from medical/scientific encoders; exotic CMYK JPEGs written by nonstandard encoders; corrupted SOF/marker data implying an invalid colorspace.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterBase.cs:75

    /// <summary>
    /// Gets the maximum value of a sample
    /// </summary>
    private float MaximumValue { get; }

    /// <summary>
    /// Gets the half of the maximum value of a sample
    /// </summary>
    private float HalfValue { get; }

    /// <summary>
    /// Returns the <see cref="JpegColorConverterBase"/> corresponding to the given <see cref="JpegColorSpace"/>
    /// </summary>
    /// <param name="colorSpace">The color space.</param>
    /// <param name="precision">The precision in bits.</param>
    /// <exception cref="InvalidImageContentException">Invalid colorspace.</exception>
    public static JpegColorConverterBase GetConverter(JpegColorSpace colorSpace, int precision)
        => Array.Find(Converters, c => c.ColorSpace == colorSpace && c.Precision == precision)
        ?? throw new InvalidImageContentException($"Could not find any converter for JpegColorSpace {colorSpace}!");

    /// <summary>
    /// Converts planar jpeg component values in <paramref name="values"/> to RGB color space in-place.
    /// </summary>
    /// <param name="values">The input/output as a stack-only <see cref="ComponentValues"/> struct</param>
    public abstract void ConvertToRgbInPlace(in ComponentValues values);

    /// <summary>
    /// Converts RGB lanes to jpeg component values.
    /// </summary>
    /// <param name="values">Jpeg component values.</param>
    /// <param name="rLane">Red colors lane.</param>
    /// <param name="gLane">Green colors lane.</param>
    /// <param name="bLane">Blue colors lane.</param>
    public abstract void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane);

    /// <summary>
    /// Returns the <see cref="JpegColorConverterBase"/>s for all supported color spaces and precisions.

View on GitHub (pinned to 59ce6af6fc)