{"record":{"id":"2434f60c5826750e","repo":"SixLabors/ImageSharp","slug":"target-icc-profile-is-missing","errorCode":null,"errorMessage":"Target ICC profile is missing.","messagePattern":"Target ICC profile is missing\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs","lineNumber":75,"sourceCode":"    /// <returns>\n    /// A color value in the target color profile, resulting from the ICC profile-based conversion of the source value.\n    /// </returns>\n    /// <exception cref=\"InvalidOperationException\">\n    /// Thrown if either the source or target ICC profile is missing from the converter options.\n    /// </exception>\n    internal static TTo ConvertUsingIccProfile<TFrom, TTo>(this ColorProfileConverter converter, in TFrom source)\n        where TFrom : struct, IColorProfile<TFrom>\n        where TTo : struct, IColorProfile<TTo>\n    {\n        // TODO: Validation of ICC Profiles against color profile. Is this possible?\n        if (converter.Options.SourceIccProfile is null)\n        {\n            throw new InvalidOperationException(\"Source ICC profile is missing.\");\n        }\n\n        if (converter.Options.TargetIccProfile is null)\n        {\n            throw new InvalidOperationException(\"Target ICC profile is missing.\");\n        }\n\n        ConversionParams sourceParams = new(converter.Options.SourceIccProfile, toPcs: true);\n        ConversionParams targetParams = new(converter.Options.TargetIccProfile, toPcs: false);\n\n        ColorProfileConverter pcsConverter = new(new ColorConversionOptions\n        {\n            MemoryAllocator = converter.Options.MemoryAllocator,\n            SourceWhitePoint = KnownIlluminants.D50Icc,\n            TargetWhitePoint = KnownIlluminants.D50Icc\n        });\n\n        // Normalize the source, then convert to the PCS space.\n        Vector4 sourcePcs = sourceParams.Converter.Calculate(source.ToScaledVector4());\n\n        // If both profiles need PCS adjustment, they both share the same unadjusted PCS space\n        // cancelling out the need to make the adjustment\n        // except if using TRC transforms, which always requires perceptual handling","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs#L57-L93","documentation":"ConvertUsingIccProfile requires a destination ICC profile, but converter.Options.TargetIccProfile was null. After mapping colors into the Profile Connection Space via the source profile, the converter needs the target profile to map PCS values into the destination device space; without it the conversion is undefined, so the library throws.","triggerScenarios":"Calling ConvertUsingIccProfile when ColorConversionOptions.TargetIccProfile was never assigned (with or without SourceIccProfile set).","commonSituations":"Building options incrementally and forgetting the target; intending 'keep colors as-is' but still selecting the ICC path; copying configuration code and dropping the TargetIccProfile line.","solutions":["Assign options.TargetIccProfile to a valid IccProfile describing the destination color space.","For standard sRGB output, load/embed a known sRGB ICC profile as the target.","If you do not actually need ICC conversion, use the non-ICC ColorProfileConverter.Convert API."],"exampleFix":"// before\nvar options = new ColorConversionOptions { SourceIccProfile = image.Metadata.IccProfile };\nvar converter = new ColorProfileConverter(options);\nconverter.ConvertUsingIccProfile<Rgb24, CieLab>(pixel);\n\n// after\nvar options = new ColorConversionOptions\n{\n    SourceIccProfile = image.Metadata.IccProfile,\n    TargetIccProfile = srgbProfile\n};\nvar converter = new ColorProfileConverter(options);\nconverter.ConvertUsingIccProfile<Rgb24, CieLab>(pixel);","handlingStrategy":"validation","validationCode":"if (converter.Options.TargetIccProfile is null)\n    throw new InvalidOperationException(\"Set TargetIccProfile before ICC conversion.\");","typeGuard":"bool HasTargetProfile(ColorProfileConverter c) => c.Options.TargetIccProfile is not null;","tryCatchPattern":"try { converter.ConvertUsingIccProfile<TFrom, TTo>(in color); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Target ICC profile is missing\"))\n{ /* configure a target profile and retry */ }","preventionTips":["Build ColorConversionOptions via a helper that requires both profiles.","Cache a standard sRGB profile instance as the default target.","Never leave TargetIccProfile null when choosing the ICC conversion path."],"tags":["icc","color-management","missing-profile","invalid-operation"],"backgroundTag":"missing-required-argument","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"}