{"record":{"id":"2fb7ce67ff770aa1","repo":"SixLabors/ImageSharp","slug":"target-icc-profile-is-missing-2fb7ce","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/ColorProfileConverterExtensionsPixelCompatible.cs","lineNumber":49,"sourceCode":"    /// image.\n    /// </param>\n    /// <exception cref=\"InvalidOperationException\">\n    /// Thrown if the converter's source or target ICC profile is not specified.\n    /// </exception>\n    public static void Convert<TPixel>(this ColorProfileConverter converter, Image<TPixel> source)\n        where TPixel : unmanaged, IPixel<TPixel>\n    {\n        // These checks actually take place within the converter, but we want to fail fast here.\n        // Note. we do not check to see whether the profiles themselves are RGB compatible,\n        // if they are not, then the converter will simply produce incorrect results.\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        // Process the rows in parallel chunks, the converter itself is thread safe.\n        source.Mutate(o => o.ProcessPixelRowsAsVector4(\n            row =>\n            {\n                // Gather and convert the pixels in the row to Rgb.\n                using IMemoryOwner<Rgb> rgbBuffer = converter.Options.MemoryAllocator.Allocate<Rgb>(row.Length);\n                Span<Rgb> rgbSpan = rgbBuffer.Memory.Span;\n                Rgb.FromScaledVector4(row, rgbSpan);\n\n                // Perform the actual color conversion.\n                converter.ConvertUsingIccProfile<Rgb, Rgb>(rgbSpan, rgbSpan);\n\n                // Copy the converted Rgb pixels back to the row as TPixel.\n                // Important: Preserve alpha from the existing row Vector4 values.\n                // We merge RGB from rgbSpan into row, leaving W untouched.\n                ref float srcRgb = ref Unsafe.As<Rgb, float>(ref MemoryMarshal.GetReference(rgbSpan));","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsPixelCompatible.cs#L31-L67","documentation":"The same fast-fail check in Convert also requires converter.Options.TargetIccProfile to be set. Without a target profile the converter does not know which color space to transform pixels into, so it throws InvalidOperationException before any processing.","triggerScenarios":"Calling the ICC conversion extension with ColorConversionOptions.TargetIccProfile left null (source profile set but target forgotten).","commonSituations":"Copy-pasting converter setup and deleting the target line; dynamically building options where the target profile load from disk failed and returned null; trying to normalize pixels without choosing a destination space.","solutions":["Set converter.Options.TargetIccProfile to a valid IccProfile before calling Convert.","Verify the target profile loaded successfully (e.g. from file or embedded resource) before constructing the options.","Choose an explicit well-known target (sRGB, Adobe RGB, etc.) matching your output intent."],"exampleFix":"// before\nvar options = new ColorConversionOptions { SourceIccProfile = src }; // target missing\n// after\nvar options = new ColorConversionOptions { SourceIccProfile = src, TargetIccProfile = LoadSRgbProfile() };","handlingStrategy":"validation","validationCode":"if (converter.Options.TargetIccProfile is null)\n{\n    throw new InvalidOperationException(\"Assign a TargetIccProfile before converting.\");\n}","typeGuard":"static bool HasTargetProfile(ColorProfileConverter c) => c.Options.TargetIccProfile is not null;","tryCatchPattern":"try { source.ConvertProfiles(converter); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Target ICC profile is missing\")) { /* assign target profile and retry */ }","preventionTips":["Require both profiles in your converter factory method (constructor parameters, not optional).","Fail at configuration-load time if the target profile file/resource is missing.","Default to a well-known target such as sRGB when the caller doesn't specify one."],"tags":["icc","color-management","null-argument","csharp"],"backgroundTag":"missing-required-config-field","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"}