{"record":{"id":"c8ad8469103d8460","repo":"SixLabors/ImageSharp","slug":"source-icc-profile-is-missing","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/ColorProfileConverterExtensionsIcc.cs","lineNumber":70,"sourceCode":"    /// </remarks>\n    /// <typeparam name=\"TFrom\">The type representing the source color profile. Must implement <see cref=\"IColorProfile{TFrom}\"/>.</typeparam>\n    /// <typeparam name=\"TTo\">The type representing the destination color profile. Must implement <see cref=\"IColorProfile{TTo}\"/>.</typeparam>\n    /// <param name=\"converter\">The color profile converter configured with source and target ICC profiles.</param>\n    /// <param name=\"source\">The color value to convert, defined in the source color profile.</param>\n    /// <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.","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs#L52-L88","documentation":"ConvertUsingIccProfile requires both a source and a target ICC profile in converter.Options, but SourceIccProfile was null. ICC-based conversion transforms colors by going device->PCS->device through the profile data, so without a source profile the converter cannot know how to interpret the incoming colors. The library throws InvalidOperationException instead of silently falling back to a default profile.","triggerScenarios":"Calling any ColorProfileConverterExtensions.ConvertUsingIccProfile<TFrom,TTo> overload (single-value or span) when ColorConversionOptions.SourceIccProfile was never assigned.","commonSituations":"Constructing a ColorProfileConverter with new ColorConversionOptions() and only setting TargetIccProfile (or neither); decoding an image without an embedded ICC profile and assuming a default source profile is used; refactoring code that previously used the built-in (non-ICC) conversion path.","solutions":["Set options.SourceIccProfile to an IccProfile (e.g. parsed from image.Metadata.IccProfile or a known sRGB profile) before calling ConvertUsingIccProfile.","If the image has an embedded profile, pass it through: new ColorConversionOptions { SourceIccProfile = image.Metadata.IccProfile, TargetIccProfile = ... }.","If no profile is available, use the non-ICC Convert method or assign a bundled standard profile such as sRGB v2 instead."],"exampleFix":"// before\nvar converter = new ColorProfileConverter(new ColorConversionOptions\n{\n    TargetIccProfile = adobeRgb\n});\nvar rgb = converter.ConvertUsingIccProfile<Rgb24, Rgb24>(pixel);\n\n// after\nvar converter = new ColorProfileConverter(new ColorConversionOptions\n{\n    SourceIccProfile = image.Metadata.IccProfile ?? IccProfileExtensions.CreateSrgbProfile(),\n    TargetIccProfile = adobeRgb\n});\nvar rgb = converter.ConvertUsingIccProfile<Rgb24, Rgb24>(pixel);","handlingStrategy":"validation","validationCode":"if (converter.Options.SourceIccProfile is null)\n    throw new InvalidOperationException(\"Set SourceIccProfile before ICC conversion.\");","typeGuard":"bool HasSourceProfile(ColorProfileConverter c) => c.Options.SourceIccProfile is not null;","tryCatchPattern":"try { converter.ConvertUsingIccProfile<TFrom, TTo>(in color); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Source ICC profile is missing\"))\n{ /* fall back to default profile or non-ICC conversion */ }","preventionTips":["Always populate both SourceIccProfile and TargetIccProfile when creating ColorConversionOptions.","Use image.Metadata.IccProfile with a null-check and an sRGB fallback.","Wrap converter construction in a factory that enforces non-null profiles."],"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"}