{"record":{"id":"2d219d1619a46fb9","repo":"SixLabors/ImageSharp","slug":"invalid-conversion-method","errorCode":null,"errorMessage":"Invalid conversion method.","messagePattern":"Invalid conversion method\\.","errorType":"exception","errorClass":"InvalidIccProfileException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs","lineNumber":53,"sourceCode":"                                InitD(profile, IccProfileTag.BToD1),\n            ConversionMethod.D2 => toPcs ?\n                                InitD(profile, IccProfileTag.DToB2) :\n                                InitD(profile, IccProfileTag.BToD2),\n            ConversionMethod.D3 => toPcs ?\n                                InitD(profile, IccProfileTag.DToB3) :\n                                InitD(profile, IccProfileTag.BToD3),\n            ConversionMethod.A0 => toPcs ?\n                                InitA(profile, IccProfileTag.AToB0) :\n                                InitA(profile, IccProfileTag.BToA0),\n            ConversionMethod.A1 => toPcs ?\n                                InitA(profile, IccProfileTag.AToB1) :\n                                InitA(profile, IccProfileTag.BToA1),\n            ConversionMethod.A2 => toPcs ?\n                                InitA(profile, IccProfileTag.AToB2) :\n                                InitA(profile, IccProfileTag.BToA2),\n            ConversionMethod.ColorTrc => InitColorTrc(profile, toPcs),\n            ConversionMethod.GrayTrc => InitGrayTrc(profile, toPcs),\n            _ => throw new InvalidIccProfileException(\"Invalid conversion method.\"),\n        };\n\n    private static IVector4Calculator InitA(IccProfile profile, IccProfileTag tag)\n        => GetTag(profile, tag) switch\n        {\n            IccLut8TagDataEntry lut8 => new LutEntryCalculator(lut8),\n            IccLut16TagDataEntry lut16 => new LutEntryCalculator(lut16),\n            IccLutAToBTagDataEntry lutAtoB => new LutABCalculator(lutAtoB),\n            IccLutBToATagDataEntry lutBtoA => new LutABCalculator(lutBtoA),\n            _ => throw new InvalidIccProfileException($\"Invalid entry {tag}.\"),\n        };\n\n    private static IVector4Calculator InitD(IccProfile profile, IccProfileTag tag)\n    {\n        IccMultiProcessElementsTagDataEntry entry = GetTag<IccMultiProcessElementsTagDataEntry>(profile, tag)\n            ?? throw new InvalidIccProfileException(\"Entry is null.\");\n\n        throw new NotImplementedException(\"Multi process elements are not supported\");","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs#L35-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use one of the defined ConversionMethod members (Matrix, A1/A2/B1/B2 per direction, ColorTrc, GrayTrc).","If the value comes from config, validate it with Enum.IsDefined before casting and default to a supported method.","If saved by a newer library version, upgrade the ImageSharp package or remap the method."],"exampleFix":"// before\nvar method = (ConversionMethod)storedInt; // may be out of range\n// after\nvar method = Enum.IsDefined(typeof(ConversionMethod), storedInt)\n    ? (ConversionMethod)storedInt\n    : ConversionMethod.ColorTrc;","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(ConversionMethod), method))\n{\n    throw new InvalidDataException($\"Unknown ConversionMethod: {method}\");\n}","typeGuard":"static bool IsValidConversionMethod(ConversionMethod m) => Enum.IsDefined(typeof(ConversionMethod), m);","tryCatchPattern":"try { var converter = new IccConverter(profile, method); }\ncatch (InvalidIccProfileException ex) when (ex.Message == \"Invalid conversion method.\") { /* clamp to a supported method and rebuild */ }","preventionTips":["Never cast raw ints/strings to ConversionMethod without Enum.IsDefined / Enum.TryParse.","Guard against config saved by newer library versions with unsupported enum values.","Centralize ConversionMethod parsing with a validated mapper."],"tags":["icc","color-management","invalid-enum-value","csharp"],"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"}