SixLabors/ImageSharp · error · InvalidIccProfileException

Invalid CurveSegment type of

Error message

Invalid CurveSegment type of {value.Signature}

What it means

When writing a one-dimensional curve set, each CurveSegment must have a known signature (formulaCurve or sampledCurve). If an IccCurveSegment carries an unknown signature - typically because it was default-constructed, corrupted, or came from an unsupported source - the writer cannot serialize it and throws.

Solutions

  1. Ensure every IccCurveSegment added to the curve has Signature set to FormulaCurve or SampledCurve and its payload populated.
  2. Populate the appropriate element (IccFormulaCurveElement or IccSampledCurveElement) instead of using a default struct.
  3. If round-tripping a profile that hit this, the source profile used an unsupported segment type - convert or drop that segment.

Example fix

// before: default segment, signature unset
var segment = default(IccCurveSegment);
curve.Segments.Add(segment);

// after: explicitly build a formula curve segment
curve.Segments.Add(new IccCurveSegment(
    IccCurveSegmentSignature.FormulaCurve,
    new IccFormulaCurveElement(IccFormulaCurveType.Type1, 1, 1, 0, 0, 0)));
Defensive patterns

Strategy: validation

Validate before calling

// Ensure every curve segment has a supported signature before writing
static bool AllSegmentsSupported(IccOneDimensionalCurve curve)
    => curve.Segments.All(s =>
        s.Signature == IccCurveSegmentSignature.FormulaCurve ||
        s.Signature == IccCurveSegmentSignature.SampledCurve);

Try / catch

try { writer.WriteOneDimensionalCurve(curve); }
catch (InvalidIccProfileException ex)
{
    // rebuild curve with explicit formula/sampled segments
    curve = RebuildCurveWithExplicitSegments();
    writer.WriteOneDimensionalCurve(curve);
}

Prevention

When it happens

Trigger: Calling IccDataWriter.WriteCurveSegment / WriteOneDimensionalCurve with an IccOneDimensionalCurve whose segments include an element whose Signature is neither FormulaCurve nor SampledCurve (e.g. default(IccCurveSegment) or a value read from an unsupported profile).

Common situations: Building ICC profiles programmatically with a partially initialized IccCurveSegment struct; round-tripping profiles containing unrecognized segment types and re-serializing them.

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


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

Appendix: source

Thrown at src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs:124

    /// <summary>
    /// Writes a <see cref="IccCurveSegment"/>
    /// </summary>
    /// <param name="value">The curve to write</param>
    /// <returns>The number of bytes written</returns>
    public int WriteCurveSegment(IccCurveSegment value)
    {
        int count = this.WriteUInt32((uint)value.Signature);
        count += this.WriteEmpty(4);

        switch (value.Signature)
        {
            case IccCurveSegmentSignature.FormulaCurve:
                return count + this.WriteFormulaCurveElement((IccFormulaCurveElement)value);
            case IccCurveSegmentSignature.SampledCurve:
                return count + this.WriteSampledCurveElement((IccSampledCurveElement)value);
            default:
                throw new InvalidIccProfileException($"Invalid CurveSegment type of {value.Signature}");
        }
    }

    /// <summary>
    /// Writes a <see cref="IccFormulaCurveElement"/>
    /// </summary>
    /// <param name="value">The curve to write</param>
    /// <returns>The number of bytes written</returns>
    public int WriteFormulaCurveElement(IccFormulaCurveElement value)
    {
        int count = this.WriteUInt16((ushort)value.Type);
        count += this.WriteEmpty(2);

        if (value.Type == IccFormulaCurveType.Type1 || value.Type == IccFormulaCurveType.Type2)
        {
            count += this.WriteSingle(value.Gamma);
        }

View on GitHub (pinned to 59ce6af6fc)