{"record":{"id":"cfb3fa7dd946e5e7","repo":"SixLabors/ImageSharp","slug":"source-icc-profile-is-missing-cfb3fa","errorCode":null,"errorMessage":"Source ICC profile is missing.","messagePattern":"Source ICC profile is missing\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsPixelCompatible.cs","lineNumber":44,"sourceCode":"    /// </remarks>\n    /// <typeparam name=\"TPixel\">The pixel format.</typeparam>\n    /// <param name=\"converter\">The color profile converter configured with source and target ICC profiles.</param>\n    /// <param name=\"source\">\n    /// The image whose pixel data will be converted. The conversion is performed in place, modifying the original\n    /// 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);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsPixelCompatible.cs#L26-L62","documentation":"ColorProfileConverterExtensionsPixelCompatible.Convert fails fast before running the ICC converter when converter.Options.SourceIccProfile is null. The library requires both a source and target ICC profile to perform the color transformation; without the source profile the pixel data's color space cannot be interpreted.","triggerScenarios":"Calling the ICC conversion extension (Convert) with an IccConverter whose Options.SourceIccProfile was never set (left null on ColorConversionOptions).","commonSituations":"Building a ColorProfileConverter and setting only TargetIccProfile; forgetting to assign an embedded or explicitly-provided source profile when the image itself has no embedded ICC profile; deserializing converter options from config where the source profile key was omitted.","solutions":["Set converter.Options.SourceIccProfile to a valid IccProfile before calling Convert.","If the source image has an embedded profile, read it from image metadata and assign it instead of leaving it null.","If no profile is available, pick the correct well-known profile (e.g. sRGB) for the actual source color space."],"exampleFix":"// before\nvar converter = new ColorProfileConverter(new ColorConversionOptions { TargetIccProfile = target });\nsource.Convert(converter);\n// after\nvar converter = new ColorProfileConverter(new ColorConversionOptions\n{\n    SourceIccProfile = sourceProfile, // must be non-null\n    TargetIccProfile = target\n});\nsource.Convert(converter);","handlingStrategy":"validation","validationCode":"if (converter.Options.SourceIccProfile is null)\n{\n    throw new InvalidOperationException(\"Assign a SourceIccProfile before converting.\");\n}","typeGuard":"static bool HasSourceProfile(ColorProfileConverter c) => c.Options.SourceIccProfile is not null;","tryCatchPattern":"try { source.ConvertProfiles(converter); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Source ICC profile is missing\")) { /* assign profile and retry */ }","preventionTips":["Always set both SourceIccProfile and TargetIccProfile when building ColorConversionOptions.","Extract the embedded profile from image metadata when available instead of leaving it null.","Centralize converter construction in one factory so profiles can't be omitted."],"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"}