SixLabors/ImageSharp · error · InvalidOperationException

Source ICC profile is missing.

Error message

Source ICC profile is missing.

What it means

ColorProfileConverterExtensionsPixelCompatible.Convert fails fast before running the ICC converter when converter.Options.SourceIccProfile is null. The library requires both a source and target ICC profile to perform the color transformation; without the source profile the pixel data's color space cannot be interpreted.

Solutions

  1. Set converter.Options.SourceIccProfile to a valid IccProfile before calling Convert.
  2. If the source image has an embedded profile, read it from image metadata and assign it instead of leaving it null.
  3. If no profile is available, pick the correct well-known profile (e.g. sRGB) for the actual source color space.

Example fix

// before
var converter = new ColorProfileConverter(new ColorConversionOptions { TargetIccProfile = target });
source.Convert(converter);
// after
var converter = new ColorProfileConverter(new ColorConversionOptions
{
    SourceIccProfile = sourceProfile, // must be non-null
    TargetIccProfile = target
});
source.Convert(converter);
Defensive patterns

Strategy: validation

Validate before calling

if (converter.Options.SourceIccProfile is null)
{
    throw new InvalidOperationException("Assign a SourceIccProfile before converting.");
}

Type guard

static bool HasSourceProfile(ColorProfileConverter c) => c.Options.SourceIccProfile is not null;

Try / catch

try { source.ConvertProfiles(converter); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Source ICC profile is missing")) { /* assign profile and retry */ }

Prevention

When it happens

Trigger: Calling the ICC conversion extension (Convert) with an IccConverter whose Options.SourceIccProfile was never set (left null on ColorConversionOptions).

Common situations: Building a ColorProfileConverter and setting only TargetIccProfile; forgetting to assign an embedded or explicitly-provided source profile when the image itself has no embedded ICC profile; deserializing converter options from config where the source profile key was omitted.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsPixelCompatible.cs:44

    /// </remarks>
    /// <typeparam name="TPixel">The pixel format.</typeparam>
    /// <param name="converter">The color profile converter configured with source and target ICC profiles.</param>
    /// <param name="source">
    /// The image whose pixel data will be converted. The conversion is performed in place, modifying the original
    /// image.
    /// </param>
    /// <exception cref="InvalidOperationException">
    /// Thrown if the converter's source or target ICC profile is not specified.
    /// </exception>
    public static void Convert<TPixel>(this ColorProfileConverter converter, Image<TPixel> source)
        where TPixel : unmanaged, IPixel<TPixel>
    {
        // These checks actually take place within the converter, but we want to fail fast here.
        // Note. we do not check to see whether the profiles themselves are RGB compatible,
        // if they are not, then the converter will simply produce incorrect results.
        if (converter.Options.SourceIccProfile is null)
        {
            throw new InvalidOperationException("Source ICC profile is missing.");
        }

        if (converter.Options.TargetIccProfile is null)
        {
            throw new InvalidOperationException("Target ICC profile is missing.");
        }

        // Process the rows in parallel chunks, the converter itself is thread safe.
        source.Mutate(o => o.ProcessPixelRowsAsVector4(
            row =>
            {
                // Gather and convert the pixels in the row to Rgb.
                using IMemoryOwner<Rgb> rgbBuffer = converter.Options.MemoryAllocator.Allocate<Rgb>(row.Length);
                Span<Rgb> rgbSpan = rgbBuffer.Memory.Span;
                Rgb.FromScaledVector4(row, rgbSpan);

                // Perform the actual color conversion.
                converter.ConvertUsingIccProfile<Rgb, Rgb>(rgbSpan, rgbSpan);

View on GitHub (pinned to 59ce6af6fc)