{"record":{"id":"171ec55e9776d4a1","repo":"dotnet/wpf","slug":"new-argumentnullexception-nameof-destinationprofile","errorCode":null,"errorMessage":"new ArgumentNullException(nameof(destinationProfile))","messagePattern":"new ArgumentNullException\\(nameof\\(destinationProfile\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorTransformHelper.cs","lineNumber":64,"sourceCode":"    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();\n                handles[1] = destinationProfile.DangerousGetHandle();\n\n                UInt32[] dwIntents = new UInt32[2] {INTENT_PERCEPTUAL, INTENT_PERCEPTUAL};\n\n                // No need to get rid of the old handle as it will get GC'ed","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorTransformHelper.cs#L46-L82","documentation":"ColorTransformHelper.CreateTransform throws ArgumentNullException(nameof(destinationProfile)) when the destinationProfile handle is null or invalid. Both source and destination ICC profile handles must be live for Mscms to build the color transform.","triggerScenarios":"Calling CreateTransform with destinationProfile null or with a handle wrapping IntPtr.Zero / a disposed profile, e.g. the destination ColorContext failed to load its profile.","commonSituations":"Destination profile file missing so its handle is invalid; passing default(null) destination to rely on a profile that was never created; disposed profiles due to ordering bugs.","solutions":["Verify destinationProfile != null && !destinationProfile.IsInvalid before calling CreateTransform","Load the destination profile from a valid ColorContext/PixelFormats standard profile first","Catch ArgumentNullException and substitute the sRGB destination profile","Fix the destination profile load failure (path, deployment, ICC validity)"],"exampleFix":"// before\nhelper.CreateTransform(srcHandle, dstHandle); // dstHandle invalid\n// after\nif (dstHandle == null || dstHandle.IsInvalid) { dstHandle = new ColorContext(PixelFormats.Srgb).GetProfileHandle(); } helper.CreateTransform(srcHandle, dstHandle);","handlingStrategy":"validation","validationCode":"if (destinationProfile == null || destinationProfile.IsInvalid) throw new InvalidOperationException(\"Destination profile must be loaded before CreateTransform\");","typeGuard":"bool HasValidDestination(SafeProfileHandle h) => h != null && !h.IsInvalid;","tryCatchPattern":"try { helper.CreateTransform(src, dst); } catch (ArgumentNullException) { dst = new ColorContext(PixelFormats.Srgb).ProfileHandle; helper.CreateTransform(src, dst); }","preventionTips":["Verify both profiles loaded before transform creation","Validate handles with IsInvalid checks","Substitute standard profiles when destination load fails"],"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"}