SixLabors/ImageSharp · error · InvalidIccProfileException

Invalid conversion method.

Error message

Invalid conversion method.

What it means

IccConverterBase.Init switches over the requested ConversionMethod (matrix, LutA/B per direction, ColorTrc, GrayTrc); the default arm throws InvalidIccProfileException("Invalid conversion method.") when the method value is not one of the supported enum members. Reaching it means the converter was asked to run with an undefined or out-of-range ConversionMethod.

Solutions

  1. Use one of the defined ConversionMethod members (Matrix, A1/A2/B1/B2 per direction, ColorTrc, GrayTrc).
  2. If the value comes from config, validate it with Enum.IsDefined before casting and default to a supported method.
  3. If saved by a newer library version, upgrade the ImageSharp package or remap the method.

Example fix

// before
var method = (ConversionMethod)storedInt; // may be out of range
// after
var method = Enum.IsDefined(typeof(ConversionMethod), storedInt)
    ? (ConversionMethod)storedInt
    : ConversionMethod.ColorTrc;
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(ConversionMethod), method))
{
    throw new InvalidDataException($"Unknown ConversionMethod: {method}");
}

Type guard

static bool IsValidConversionMethod(ConversionMethod m) => Enum.IsDefined(typeof(ConversionMethod), m);

Try / catch

try { var converter = new IccConverter(profile, method); }
catch (InvalidIccProfileException ex) when (ex.Message == "Invalid conversion method.") { /* clamp to a supported method and rebuild */ }

Prevention

When it happens

Trigger: Constructing an IccConverter (via Init, called from the constructor) with ConversionMethod set to a value outside the defined enum set — e.g. default(int)-cast enum, config-derived integer, or a newer enum value unsupported by this assembly version.

Common situations: Persisting ConversionMethod as an int/ string in config and casting it back without validation; deserializing settings saved by a newer library version; manually constructing converters with an invalid cast.

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/2d219d1619a46fb9. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs:53

                                InitD(profile, IccProfileTag.BToD1),
            ConversionMethod.D2 => toPcs ?
                                InitD(profile, IccProfileTag.DToB2) :
                                InitD(profile, IccProfileTag.BToD2),
            ConversionMethod.D3 => toPcs ?
                                InitD(profile, IccProfileTag.DToB3) :
                                InitD(profile, IccProfileTag.BToD3),
            ConversionMethod.A0 => toPcs ?
                                InitA(profile, IccProfileTag.AToB0) :
                                InitA(profile, IccProfileTag.BToA0),
            ConversionMethod.A1 => toPcs ?
                                InitA(profile, IccProfileTag.AToB1) :
                                InitA(profile, IccProfileTag.BToA1),
            ConversionMethod.A2 => toPcs ?
                                InitA(profile, IccProfileTag.AToB2) :
                                InitA(profile, IccProfileTag.BToA2),
            ConversionMethod.ColorTrc => InitColorTrc(profile, toPcs),
            ConversionMethod.GrayTrc => InitGrayTrc(profile, toPcs),
            _ => throw new InvalidIccProfileException("Invalid conversion method."),
        };

    private static IVector4Calculator InitA(IccProfile profile, IccProfileTag tag)
        => GetTag(profile, tag) switch
        {
            IccLut8TagDataEntry lut8 => new LutEntryCalculator(lut8),
            IccLut16TagDataEntry lut16 => new LutEntryCalculator(lut16),
            IccLutAToBTagDataEntry lutAtoB => new LutABCalculator(lutAtoB),
            IccLutBToATagDataEntry lutBtoA => new LutABCalculator(lutBtoA),
            _ => throw new InvalidIccProfileException($"Invalid entry {tag}."),
        };

    private static IVector4Calculator InitD(IccProfile profile, IccProfileTag tag)
    {
        IccMultiProcessElementsTagDataEntry entry = GetTag<IccMultiProcessElementsTagDataEntry>(profile, tag)
            ?? throw new InvalidIccProfileException("Entry is null.");

        throw new NotImplementedException("Multi process elements are not supported");

View on GitHub (pinned to 59ce6af6fc)