{"record":{"id":"0a97567143a2de63","repo":"dotnet/wpf","slug":"sr-format-sr-color-dimensionmismatch-null","errorCode":null,"errorMessage":"SR.Format(SR.Color_DimensionMismatch, null)","messagePattern":"SR\\.Format\\(SR\\.Color_DimensionMismatch, null\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Color.cs","lineNumber":70,"sourceCode":"                    c1.nativeColorValue[i] = 0.0f;\n                }\n            }\n\n            c1.isFromScRgb = false;\n\n            return c1;\n        }\n\n        ///<summary>\n        /// FromAValues - general constructor for multichannel color values with explicit alpha channel and color context, i.e. spectral colors\n        ///</summary>\n        public static Color FromAValues(float a, float[] values, Uri profileUri)\n        {\n            Color c1 = Color.FromProfile(profileUri);\n\n            if (values == null)\n            {\n                throw new ArgumentException(SR.Format(SR.Color_DimensionMismatch, null));\n            }\n\n            if (values.Length != c1.nativeColorValue.Length)\n            {\n                throw new ArgumentException(SR.Format(SR.Color_DimensionMismatch, null));\n            }\n\n            for (int numChannels = 0; numChannels < values.Length; numChannels++)\n            {\n                c1.nativeColorValue[numChannels] = values[numChannels];\n            }\n            c1.ComputeScRgbValues();\n            c1.scRgbColor.a = a;\n            if (a < 0.0f)\n            {\n                a = 0.0f;\n            }\n            else if (a > 1.0f)","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Color.cs#L52-L88","documentation":"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.","triggerScenarios":"Calling Color.FromAValues(a, null, profileUri) — passing null for the float[] values parameter.","commonSituations":"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.","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"],"exampleFix":"// before\n Color c = Color.FromAValues(1.0f, null, profileUri);\n// after\n Color c = Color.FromAValues(1.0f, new float[] {0.5f, 0.5f, 0.5f}, profileUri);","handlingStrategy":"validation","validationCode":"if (values == null) throw new InvalidOperationException(\"channel values required before Color.FromAValues\");","typeGuard":"bool HasChannelValues(float[] values) => values != null && values.Length > 0;","tryCatchPattern":"try { var c = Color.FromAValues(a, values, uri); } catch (ArgumentException ex) { /* values was null or wrong dimension */ }","preventionTips":["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"],"tags":["wpf","color","argument-null","array"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}