{"record":{"id":"959f42737ed60ab5","repo":"dotnet/wpf","slug":"new-argumentnullexception-nameof-sourceprofile","errorCode":null,"errorMessage":"new ArgumentNullException(nameof(sourceProfile))","messagePattern":"new ArgumentNullException\\(nameof\\(sourceProfile\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorTransformHelper.cs","lineNumber":59,"sourceCode":"    #region ColorTransformHelper\n\n    /// <summary>\n    /// Class to call into MSCMS color transform APIs\n    /// </summary>\n    internal class ColorTransformHelper\n    {\n        /// Constructor\n        internal ColorTransformHelper()\n        {\n        }\n\n        /// Creates an ICM Profile Transform\n        /// Retrieves a standard color space profile\n        internal void CreateTransform(SafeProfileHandle sourceProfile, SafeProfileHandle destinationProfile)\n        {\n            if (sourceProfile == null || sourceProfile.IsInvalid)\n            {\n                throw new ArgumentNullException(nameof(sourceProfile));\n            }\n\n            if (destinationProfile == null || destinationProfile.IsInvalid)\n            {\n                throw new ArgumentNullException(nameof(destinationProfile));\n            }\n\n            IntPtr[] handles = new IntPtr[2];\n            bool success = true;\n\n            sourceProfile.DangerousAddRef(ref success);\n            Debug.Assert(success);\n            destinationProfile.DangerousAddRef(ref success);\n            Debug.Assert(success);\n\n            try\n            {\n                handles[0] = sourceProfile.DangerousGetHandle();","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorTransformHelper.cs#L41-L77","documentation":"ColorTransformHelper.CreateTransform throws ArgumentNullException(nameof(sourceProfile)) when the sourceProfile handle is null or invalid. A valid, open source ICC profile handle is required to create the Mscms color transform.","triggerScenarios":"Calling CreateTransform with a null SafeProfileHandle or one wrapping an invalid/zero handle, e.g. when the source profile failed to load (bad URI, corrupt ICC data).","commonSituations":"A ColorContext whose profile never loaded producing an invalid handle passed straight into CreateTransform; forgetting to construct the source profile before creating the transform.","solutions":["Ensure the source profile loaded successfully (e.g. from a valid ColorContext) before calling CreateTransform","Check sourceProfile != null && !sourceProfile.IsInvalid before the call","Catch ArgumentNullException and fall back to a default sRGB source profile","Fix the root cause of the failed profile load (missing file, invalid ICC data)"],"exampleFix":"// before\nhelper.CreateTransform(srcHandle, dstHandle); // srcHandle may be invalid\n// after\nif (srcHandle == null || srcHandle.IsInvalid) { srcHandle = ColorContexts.GetStandardProfileHandle(PixelFormats.Srgb); } helper.CreateTransform(srcHandle, dstHandle);","handlingStrategy":"validation","validationCode":"if (sourceProfile == null || sourceProfile.IsInvalid) throw new InvalidOperationException(\"Source profile must be loaded before CreateTransform\");","typeGuard":"bool HasValidSource(SafeProfileHandle h) => h != null && !h.IsInvalid;","tryCatchPattern":"try { helper.CreateTransform(src, dst); } catch (ArgumentNullException) { src = GetDefaultSrgbProfile(); helper.CreateTransform(src, dst); }","preventionTips":["Always load the source ColorContext successfully before creating transforms","Check handle validity before calling CMS APIs","Fall back to standard sRGB profile on load failure"],"tags":["wpf","color-management","null-argument"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}