dotnet/wpf · error · NotSupportedException
new NotSupportedException() // standard scRGB profile does…
Error message
new NotSupportedException() // standard scRGB profile does not exist yet
What it means
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.
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.
Example fix
// before
var ctx = new ColorContext(PixelFormats.Gray8); // NotSupportedException
// after
var ctx = new ColorContext(new Uri("pack://application:,,,/Profiles/gray.icc", UriKind.Absolute)); Defensive patterns
Strategy: try-catch
Validate before calling
static readonly PixelFormat[] Unsupported = { PixelFormats.Rgba64, PixelFormats.Prgba64, PixelFormats.Rgba128Float, PixelFormats.Prgba128Float, PixelFormats.BlackWhite, PixelFormats.Gray2, PixelFormats.Gray4, PixelFormats.Gray8, PixelFormats.Gray32Float, PixelFormats.Cmyk32 };
bool hasStandardProfile(PixelFormat f) => !Unsupported.Contains(f); Type guard
bool HasStandardColorProfile(PixelFormat f) => !(new[]{"Rgba64","Prgba64","Rgba128Float","Prgba128Float","BlackWhite","Gray2","Gray4","Gray8","Gray32Float","Cmyk32"}.Any(n => f.ToString().Contains(n))); Try / catch
ColorContext ctx;
try { ctx = new ColorContext(pixelFormat); }
catch (NotSupportedException) { ctx = new ColorContext(new Uri(profilePath, UriKind.Absolute)); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- By default, ToolTip property does not support ToolTip…
- Cannot convert from type.
- Cannot convert to type.
- Cannot convert to type.
- CollectionIsFixedSize
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1737b1936b5a53a8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ColorContext.cs:194
case PixelFormatEnum.Rgb24:
case PixelFormatEnum.Bgr32:
case PixelFormatEnum.Bgra32:
case PixelFormatEnum.Pbgra32:
default:
Initialize(GetStandardColorSpaceProfile(), isStandardProfileUriNotFromUser: true);
break;
case PixelFormatEnum.Rgba64:
case PixelFormatEnum.Prgba64:
case PixelFormatEnum.Rgba128Float:
case PixelFormatEnum.Prgba128Float:
case PixelFormatEnum.BlackWhite:
case PixelFormatEnum.Gray2:
case PixelFormatEnum.Gray4:
case PixelFormatEnum.Gray8:
case PixelFormatEnum.Gray32Float:
case PixelFormatEnum.Cmyk32:
throw new NotSupportedException(); // standard scRGB profile does not exist yet
}
}
#endregion
#region Public Methods
/// <summary>
/// Returns a memory stream to the color profile bits
/// </summary>
public Stream OpenProfileStream()
{
//
// 3.* backwards compat for a "bad" ColorContext. Now the helper is a
// struct so when it's invalid we'll pretend it's a reference type. This
// should only happen if the color profile is corrupt (see early exits in
// ColorContext(SafeMILHandle) and FromRawBytes()).
//View on GitHub (pinned to 81131a70a4)