SixLabors/ImageSharp · error · InvalidIccProfileException

Invalid ICC profile.

Error message

Invalid ICC profile.

What it means

JpegDecoderCore.InitIccProfile embeds an APP2 ICC profile into the metadata only if IccProfile.CheckIsValid() passes; otherwise it throws InvalidIccProfileException. The JPEG carries an ICC profile that fails the library's structural validation.

Solutions

  1. Strip or repair the ICC profile using an image tool (e.g. exiftool/exiv2 to remove the profile) and retry
  2. Catch InvalidIccProfileException and decode without honoring color management
  3. Re-export the image from the original source with a valid sRGB profile
  4. Verify the file is not truncated — a partial profile is a common cause

Example fix

// before
using var image = Image.Load(stream); // InvalidIccProfileException
// after
try { using var image = Image.Load(stream); }
catch (InvalidIccProfileException ex)
{
    // Remove ICC: exiftool -icc_profile= file.jpg, then reload
}
Defensive patterns

Strategy: try-catch

Try / catch

try { using var image = Image.Load(stream); }
catch (InvalidIccProfileException)
{
    // Strip the ICC profile externally and retry, or decode without color management
}

Prevention

When it happens

Trigger: Decoding a JPEG containing an ICC APP2 marker whose profile data is malformed (bad header, invalid tag table, truncated profile) so CheckIsValid() returns false.

Common situations: Images processed by tools that wrote broken/corrupt ICC profiles; truncated files cutting the ICC chunk mid-profile; hand-crafted or fuzzed JPEGs; profiles stripped of required tags by downstream pipelines.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs:706

            this.Metadata.ExifProfile = new ExifProfile(this.exifData);
        }
    }

    /// <summary>
    /// Initializes the ICC profile.
    /// </summary>
    private void InitIccProfile()
    {
        if (this.hasIcc && this.Metadata.IccProfile == null)
        {
            IccProfile profile = new(this.iccData);
            if (profile.CheckIsValid())
            {
                this.Metadata.IccProfile = profile;
            }
            else
            {
                throw new InvalidIccProfileException("Invalid ICC profile.");
            }
        }
    }

    private void SetIccMetadata(IccProfile profile)
    {
        if (!this.skipMetadata && profile?.CheckIsValid() == true)
        {
            this.hasIcc = true;
            this.Metadata ??= new ImageMetadata();
            this.Metadata.IccProfile = profile;
        }
    }

    /// <summary>
    /// Initializes the IPTC profile.
    /// </summary>
    private void InitIptcProfile()

View on GitHub (pinned to 59ce6af6fc)