SixLabors/ImageSharp · error · InvalidIccProfileException
Unrecognized colorant encoding
Error message
Unrecognized colorant encoding
What it means
IccChromaticityTagDataEntry resolves colorant coordinates only for known colorant encodings (e.g. RGB, CMYK derived from the channel count / colorant type). When the stored colorant value does not map to any known encoding, the entry construction throws InvalidIccProfileException with 'Unrecognized colorant encoding'.
Solutions
- Check the colorant encoding/channel count on the source profile; only RGB and CMYK-style chromaticity encodings are supported
- Fix or regenerate the profile with a standard tool so the chromaticity tag uses a known encoding
- If you only need the raw bytes, read the tag data directly instead of constructing the typed entry
- Catch InvalidIccProfileException when loading untrusted profiles and fall back to ignoring the chromaticity tag
Example fix
// before
var entry = new IccChromaticityTagDataEntry((IccColorantEncoding)0x99, channelValues);
// after
if (Enum.IsDefined(typeof(IccColorantEncoding), encoding) && encoding != IccColorantEncoding.Unknown)
{
var entry = new IccChromaticityTagDataEntry(encoding, channelValues);
} Defensive patterns
Strategy: try-catch
Validate before calling
bool known = colorant is IccColorantEncoding.Rgb or IccColorantEncoding.Cmy or IccColorantEncoding.Cmyk or IccColorantEncoding.CmykChannel1 or IccColorantEncoding.CmykChannel2 or IccColorantEncoding.CmykChannel3;
Type guard
static bool IsKnownColorant(IccColorantEncoding e) => e is not IccColorantEncoding.Unknown && Enum.IsDefined(e);
Try / catch
try { var entry = new IccChromaticityTagDataEntry(encoding, values); } catch (InvalidIccProfileException ex) { log.Warn(ex, "Unrecognized chromaticity colorant; skipping tag"); } Prevention
- Only load chromaticity tags with RGB/CMYK-style encodings
- Validate untrusted profiles before constructing typed entries
- Handle profiles from non-conformant sources defensively
When it happens
Trigger: Constructing an IccChromaticityTagDataEntry (or Equals/GetColorantArray path) with a colorant/channel specification that does not match any supported encoding, e.g. an unexpected ColorantEncoding value combined with a channel count not covered by the switch in GetColorantArray.
Common situations: Loading a malformed or non-standard ICC profile whose chromaticity tag carries an encoding outside the ICC spec subset ImageSharp supports; hand-crafting a chromaticity tag with a wrong channel value.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Curve has to be either "IccTypeSignature.Curve" or…
- Source ICC profile is missing.
- Target ICC profile is missing.
- Source PCS to target PCS is not supported
- Source PCS is not supported
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/75cc7aad5e2261ee.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Metadata/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs:143
[0.300, 0.600],
[0.150, 0.060]
];
case IccColorantEncoding.P22:
return
[
[0.625, 0.340],
[0.280, 0.605],
[0.155, 0.070]
];
case IccColorantEncoding.SmpteRp145:
return
[
[0.630, 0.340],
[0.310, 0.595],
[0.155, 0.070]
];
default:
throw new InvalidIccProfileException("Unrecognized colorant encoding");
}
}
private bool EqualsChannelValues(IccChromaticityTagDataEntry entry)
{
if (this.ChannelValues.Length != entry.ChannelValues.Length)
{
return false;
}
for (int i = 0; i < this.ChannelValues.Length; i++)
{
if (!this.ChannelValues[i].AsSpan().SequenceEqual(entry.ChannelValues[i]))
{
return false;
}
}
View on GitHub (pinned to 59ce6af6fc)