{"record":{"id":"1737b1936b5a53a8","repo":"dotnet/wpf","slug":"new-notsupportedexception-standard-scrgb-profile-does-not","errorCode":null,"errorMessage":"new NotSupportedException() // standard scRGB profile does not exist yet","messagePattern":"new NotSupportedException\\(\\) // standard scRGB profile does not exist yet","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorContext.cs","lineNumber":194,"sourceCode":"                case PixelFormatEnum.Rgb24:\n                case PixelFormatEnum.Bgr32:\n                case PixelFormatEnum.Bgra32:\n                case PixelFormatEnum.Pbgra32:\n                default:\n                    Initialize(GetStandardColorSpaceProfile(), isStandardProfileUriNotFromUser: true);\n                    break;\n\n                case PixelFormatEnum.Rgba64:\n                case PixelFormatEnum.Prgba64:\n                case PixelFormatEnum.Rgba128Float:\n                case PixelFormatEnum.Prgba128Float:\n                case PixelFormatEnum.BlackWhite:\n                case PixelFormatEnum.Gray2:\n                case PixelFormatEnum.Gray4:\n                case PixelFormatEnum.Gray8:\n                case PixelFormatEnum.Gray32Float:\n                case PixelFormatEnum.Cmyk32:\n                    throw new NotSupportedException(); // standard scRGB profile does not exist yet\n            }\n        }\n\n        #endregion\n\n        #region Public Methods\n\n        /// <summary>\n        /// Returns a memory stream to the color profile bits\n        /// </summary>\n        public Stream OpenProfileStream()\n        {\n            //\n            // 3.* backwards compat for a \"bad\" ColorContext. Now the helper is a\n            // struct so when it's invalid we'll pretend it's a reference type. This\n            // should only happen if the color profile is corrupt (see early exits in\n            // ColorContext(SafeMILHandle) and FromRawBytes()).\n            //","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorContext.cs#L176-L212","documentation":"The ColorContext(PixelFormat) constructor throws NotSupportedException for pixel formats whose standard color profile (e.g. scRGB, grayscale float, CMYK) has no corresponding built-in standard profile in WPF. Only a subset of formats maps to a shipped standard profile.","triggerScenarios":"new ColorContext(PixelFormats.Rgba64 / Prgba64 / Rgba128Float / Prgba128Float / BlackWhite / Gray2 / Gray4 / Gray8 / Gray32Float / Cmyk32) — the switch at ColorContext.cs:194 has no standard profile for these.","commonSituations":"Building contexts for high-bit-depth or grayscale bitmaps (scanned BW/gray images, HDR float images, CMYK print pipelines) assuming every PixelFormat has a stock profile.","solutions":["Use a supported RGB format's context (e.g. new ColorContext(PixelFormats.Bgra32)) or load an explicit ICC file: new ColorContext(new Uri(\"path/to/profile.icm\", UriKind.Absolute)).","Ship your own .icm/.icc profile matching the pixel format and construct the context from its URI.","Check the format against the supported list before constructing; catch NotSupportedException and fall back to a profile-from-file context."],"exampleFix":"// before\nvar ctx = new ColorContext(PixelFormats.Gray8); // NotSupportedException\n// after\nvar ctx = new ColorContext(new Uri(\"pack://application:,,,/Profiles/gray.icc\", UriKind.Absolute));","handlingStrategy":"try-catch","validationCode":"static readonly PixelFormat[] Unsupported = { PixelFormats.Rgba64, PixelFormats.Prgba64, PixelFormats.Rgba128Float, PixelFormats.Prgba128Float, PixelFormats.BlackWhite, PixelFormats.Gray2, PixelFormats.Gray4, PixelFormats.Gray8, PixelFormats.Gray32Float, PixelFormats.Cmyk32 };\nbool hasStandardProfile(PixelFormat f) => !Unsupported.Contains(f);","typeGuard":"bool HasStandardColorProfile(PixelFormat f) => !(new[]{\"Rgba64\",\"Prgba64\",\"Rgba128Float\",\"Prgba128Float\",\"BlackWhite\",\"Gray2\",\"Gray4\",\"Gray8\",\"Gray32Float\",\"Cmyk32\"}.Any(n => f.ToString().Contains(n)));","tryCatchPattern":"ColorContext ctx;\ntry { ctx = new ColorContext(pixelFormat); }\ncatch (NotSupportedException) { ctx = new ColorContext(new Uri(profilePath, UriKind.Absolute)); }","preventionTips":["Memorize the supported list: essentially 8/16/32-bit RGB formats map to the standard sRGB profile","Ship sidecar .icc files for gray/CMYK/wide-gamut formats","Prefer explicit profile URIs over PixelFormat-derived contexts"],"tags":["wpf","color-context","pixel-format","not-supported"],"backgroundTag":"unsupported-enum-value","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"}