dotnet/wpf · error · ArgumentException
SR.Format(SR.Color_DimensionMismatch, null)
Error message
SR.Format(SR.Color_DimensionMismatch, null)
What it means
Color.FromAValues builds a non-sRGB color from a channel-values array that must match the channel count of the color context/profile identified by profileUri. This ArgumentException is thrown when the values array is null — no channel data was supplied.
Solutions
- Pass a non-null float[] with one element per channel of the profile
- Initialize the array with defaults (e.g. zeros) when data is unavailable
- Validate the array for null before calling FromAValues
Example fix
// before
Color c = Color.FromAValues(1.0f, null, profileUri);
// after
Color c = Color.FromAValues(1.0f, new float[] {0.5f, 0.5f, 0.5f}, profileUri); Defensive patterns
Strategy: validation
Validate before calling
if (values == null) throw new InvalidOperationException("channel values required before Color.FromAValues"); Type guard
bool HasChannelValues(float[] values) => values != null && values.Length > 0;
Try / catch
try { var c = Color.FromAValues(a, values, uri); } catch (ArgumentException ex) { /* values was null or wrong dimension */ } Prevention
- Never pass null channel arrays; default to an allocated array
- Validate inputs before constructing profile-based colors
- Ensure async data loads complete before building the Color
When it happens
Trigger: Calling Color.FromAValues(a, null, profileUri) — passing null for the float[] values parameter.
Common situations: Binding the values array to data that has not been loaded yet; refactoring code where the array became optional; conditional construction paths that skip array initialization.
Related errors
- anchorLocator.Parts
- ArgumentNullException (buffer/sourceBuffer was IntPtr.Zero)
- ArgumentNullException: handle
- ArgumentNullException(nameof(assemblyName))
- ArgumentNullException(nameof(assemblyNames))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0a97567143a2de63.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Color.cs:70
c1.nativeColorValue[i] = 0.0f;
}
}
c1.isFromScRgb = false;
return c1;
}
///<summary>
/// FromAValues - general constructor for multichannel color values with explicit alpha channel and color context, i.e. spectral colors
///</summary>
public static Color FromAValues(float a, float[] values, Uri profileUri)
{
Color c1 = Color.FromProfile(profileUri);
if (values == null)
{
throw new ArgumentException(SR.Format(SR.Color_DimensionMismatch, null));
}
if (values.Length != c1.nativeColorValue.Length)
{
throw new ArgumentException(SR.Format(SR.Color_DimensionMismatch, null));
}
for (int numChannels = 0; numChannels < values.Length; numChannels++)
{
c1.nativeColorValue[numChannels] = values[numChannels];
}
c1.ComputeScRgbValues();
c1.scRgbColor.a = a;
if (a < 0.0f)
{
a = 0.0f;
}
else if (a > 1.0f)View on GitHub (pinned to 81131a70a4)