{"record":{"id":"faddc1422c7e4438","repo":"SixLabors/ImageSharp","slug":"invalid-curvesegment-type-of-value-signature","errorCode":null,"errorMessage":"Invalid CurveSegment type of {value.Signature}","messagePattern":"Invalid CurveSegment type of (.+?)","errorType":"exception","errorClass":"InvalidIccProfileException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs","lineNumber":124,"sourceCode":"\n    /// <summary>\n    /// Writes a <see cref=\"IccCurveSegment\"/>\n    /// </summary>\n    /// <param name=\"value\">The curve to write</param>\n    /// <returns>The number of bytes written</returns>\n    public int WriteCurveSegment(IccCurveSegment value)\n    {\n        int count = this.WriteUInt32((uint)value.Signature);\n        count += this.WriteEmpty(4);\n\n        switch (value.Signature)\n        {\n            case IccCurveSegmentSignature.FormulaCurve:\n                return count + this.WriteFormulaCurveElement((IccFormulaCurveElement)value);\n            case IccCurveSegmentSignature.SampledCurve:\n                return count + this.WriteSampledCurveElement((IccSampledCurveElement)value);\n            default:\n                throw new InvalidIccProfileException($\"Invalid CurveSegment type of {value.Signature}\");\n        }\n    }\n\n    /// <summary>\n    /// Writes a <see cref=\"IccFormulaCurveElement\"/>\n    /// </summary>\n    /// <param name=\"value\">The curve to write</param>\n    /// <returns>The number of bytes written</returns>\n    public int WriteFormulaCurveElement(IccFormulaCurveElement value)\n    {\n        int count = this.WriteUInt16((ushort)value.Type);\n        count += this.WriteEmpty(2);\n\n        if (value.Type == IccFormulaCurveType.Type1 || value.Type == IccFormulaCurveType.Type2)\n        {\n            count += this.WriteSingle(value.Gamma);\n        }\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs#L106-L142","documentation":"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.","triggerScenarios":"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).","commonSituations":"Building ICC profiles programmatically with a partially initialized IccCurveSegment struct; round-tripping profiles containing unrecognized segment types and re-serializing them.","solutions":["Ensure every IccCurveSegment added to the curve has Signature set to FormulaCurve or SampledCurve and its payload populated.","Populate the appropriate element (IccFormulaCurveElement or IccSampledCurveElement) instead of using a default struct.","If round-tripping a profile that hit this, the source profile used an unsupported segment type - convert or drop that segment."],"exampleFix":"// before: default segment, signature unset\nvar segment = default(IccCurveSegment);\ncurve.Segments.Add(segment);\n\n// after: explicitly build a formula curve segment\ncurve.Segments.Add(new IccCurveSegment(\n    IccCurveSegmentSignature.FormulaCurve,\n    new IccFormulaCurveElement(IccFormulaCurveType.Type1, 1, 1, 0, 0, 0)));","handlingStrategy":"validation","validationCode":"// Ensure every curve segment has a supported signature before writing\nstatic bool AllSegmentsSupported(IccOneDimensionalCurve curve)\n    => curve.Segments.All(s =>\n        s.Signature == IccCurveSegmentSignature.FormulaCurve ||\n        s.Signature == IccCurveSegmentSignature.SampledCurve);","typeGuard":null,"tryCatchPattern":"try { writer.WriteOneDimensionalCurve(curve); }\ncatch (InvalidIccProfileException ex)\n{\n    // rebuild curve with explicit formula/sampled segments\n    curve = RebuildCurveWithExplicitSegments();\n    writer.WriteOneDimensionalCurve(curve);\n}","preventionTips":["Always construct IccCurveSegment via constructors that set Signature","Never add default(IccCurveSegment) to a curve","Only round-trip profiles the library could fully parse","Unit-test profile writers with hand-built curves"],"tags":["icc","serialization","curve-segment"],"backgroundTag":"invalid-enum-value","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}