{"record":{"id":"c6eaa0c16e90b8d4","repo":"dotnet/wpf","slug":"sr-collection-badrank","errorCode":null,"errorMessage":"SR.Collection_BadRank","messagePattern":"SR\\.Collection_BadRank","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontFaceLayoutInfo.cs","lineNumber":720,"sourceCode":"            }\n\n            public void Clear()\n            {\n                throw new NotSupportedException();\n            }\n\n            public bool Contains(KeyValuePair<int, ushort> item)\n            {\n                return ContainsKey(item.Key);\n            }\n\n            public void CopyTo(KeyValuePair<int, ushort>[] array, int arrayIndex)\n            {\n                ArgumentNullException.ThrowIfNull(array);\n\n                if (array.Rank != 1)\n                {\n                    throw new ArgumentException(SR.Collection_BadRank);\n                }\n\n                // The extra \"arrayIndex >= array.Length\" check in because even if _collection.Count\n                // is 0 the index is not allowed to be equal or greater than the length\n                // (from the MSDN ICollection docs)\n                ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);\n                ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(arrayIndex, array.Length);\n                ArgumentOutOfRangeException.ThrowIfGreaterThan(arrayIndex, array.Length - Count);\n\n                foreach (KeyValuePair<int, ushort> pair in this)\n                    array[arrayIndex++] = pair;\n            }\n\n            public int Count\n            {\n                get { return CMap.Count; }\n            }\n","sourceCodeStart":702,"sourceCodeEnd":738,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontFaceLayoutInfo.cs#L702-L738","documentation":"IntMap.CopyTo validates the destination array like any ICollection.CopyTo implementation: the array must be non-null, exactly one-dimensional (Rank == 1), and the startIndex must be in range. A multi-dimensional array is rejected with ArgumentException(SR.Collection_BadRank).","triggerScenarios":"Calling IntMap.CopyTo(some2DArray, 0) where the target array was created with more than one dimension (e.g. new KeyValuePair<int,ushort>[2,2]).","commonSituations":"Dumping glyph mappings into an array that was declared rectangular/multi-dimensional for convenience, or passing a jagged container typed as Array with rank > 1.","solutions":["Use a one-dimensional array: new KeyValuePair<int,ushort>[intMap.Count].","Check array.Rank == 1 before calling CopyTo.","Flatten multi-dimensional data into a linear array and use arrayIndex offsets."],"exampleFix":"// before\nvar dest = new KeyValuePair<int, ushort>[10, 10];\nintMap.CopyTo(dest, 0); // throws Collection_BadRank\n// after\nvar dest = new KeyValuePair<int, ushort>[intMap.Count];\nintMap.CopyTo(dest, 0);","handlingStrategy":"validation","validationCode":"if (array == null) throw new ArgumentNullException(nameof(array));\nif (array.Rank != 1) throw new ArgumentException(\"Destination must be a 1-D array.\", nameof(array));\nif (arrayIndex < 0 || arrayIndex >= array.Length) throw new ArgumentOutOfRangeException(nameof(arrayIndex));","typeGuard":"bool CanCopyTo<T>(T[] array, int index) => array != null && array.Rank == 1 && index >= 0 && index < array.Length;","tryCatchPattern":null,"preventionTips":["Always allocate 1-D arrays for CopyTo.","Check Rank == 1 when accepting arbitrary Array instances.","Size the array to the collection Count."],"tags":["wpf","fonts","argumentexception","array-rank"],"backgroundTag":"invalid-argument-value","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"}