{"record":{"id":"063fb40b1f5de6d6","repo":"dotnet/wpf","slug":"sr-collection-badrank-typefacecollection","errorCode":null,"errorMessage":"SR.Collection_BadRank","messagePattern":"SR\\.Collection_BadRank","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/TypefaceCollection.cs","lineNumber":61,"sourceCode":"        }\n\n        public bool Contains(Typeface item)\n        {\n            foreach (Typeface t in this)\n            {\n                if (t.Equals(item))\n                    return true;\n            }\n            return false;\n        }\n\n        public void CopyTo(Typeface[] 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 (Typeface t in this)\n            {\n                array[arrayIndex++] = t;\n            }\n        }\n\n        public int Count\n        {\n            get","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/TypefaceCollection.cs#L43-L79","documentation":"CopyTo validates the destination array before copying Typefaces into it. A multi-dimensional array (Rank != 1) cannot be used as an ICollection<T> copy target, so an ArgumentException with resource SR.Collection_BadRank is thrown.","triggerScenarios":"Calling TypefaceCollection.CopyTo(array, index) where array was created as a multi-dimensional array, e.g. new Typeface[2,2].","commonSituations":"Passing rectangular arrays produced elsewhere in the code, or generic serialization code that allocates multi-dimensional buffers.","solutions":["Allocate a one-dimensional Typeface[] whose length is at least the collection count","Convert any existing multi-dimensional array to a flat 1D array before copying"],"exampleFix":"// before\nvar arr = new Typeface[2, 2];\nfontFamily.Typefaces.CopyTo(arr, 0);\n// after\nvar arr = new Typeface[fontFamily.Typefaces.Count];\nfontFamily.Typefaces.CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"if (array == null) throw new ArgumentNullException(nameof(array));\nif (array.Rank != 1) throw new ArgumentException(\"1-D array required\", nameof(array));\nif (arrayIndex < 0 || arrayIndex >= array.Length) throw new ArgumentOutOfRangeException(nameof(arrayIndex));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always copy ICollection<T> data into freshly allocated 1D arrays","Remember arrayIndex must be < array.Length even for empty collections"],"tags":["wpf","fonts","array-rank","argument-exception"],"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"}