{"record":{"id":"5e835b81ee41ce9b","repo":"dotnet/wpf","slug":"collection-copyto-arraycannotbemultidimensional","errorCode":null,"errorMessage":"Collection_CopyTo_ArrayCannotBeMultidimensional","messagePattern":"Collection_CopyTo_ArrayCannotBeMultidimensional","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealDoubles.cs","lineNumber":169,"sourceCode":"                {\n                    _doubleList[i] = 0;\n                }\n            }\n        }\n\n        public bool Contains(double item)\n        {\n            return IndexOf(item) >= 0;\n        }\n\n        public void CopyTo(double[] array, int arrayIndex)\n        {\n            // parameter validations\n            ArgumentNullException.ThrowIfNull(array);\n\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(\n                    SR.Collection_CopyTo_ArrayCannotBeMultidimensional, \n                    nameof(array));                \n            }\n\n            ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);\n\n            if (arrayIndex >= array.Length)\n            {\n                throw new ArgumentException(\n                    SR.Format(\n                        SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, \n                        \"arrayIndex\", \n                        \"array\"),\n                    nameof(arrayIndex));\n            }\n\n            if ((array.Length - Count - arrayIndex) < 0)\n            {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealDoubles.cs#L151-L187","documentation":"ThousandthOfEmRealDoubles.CopyTo throws ArgumentException(SR.Collection_CopyTo_ArrayCannotBeMultidimensional) when the destination Array has Rank != 1. ICollection.CopyTo only supports single-dimensional arrays, matching the standard .NET collection contract.","triggerScenarios":"Calling CopyTo (or casting the collection to ICollection/ICollection<double> and calling CopyTo) with a multidimensional array such as double[,] as the destination.","commonSituations":"Passing a 2D array declared for grid-like storage to CopyTo; generic copy helpers that take Array instead of double[].","solutions":["Pass a single-dimensional array (double[]) as the destination","If multidimensional storage is needed, copy into a flat double[] then index-map into the 2D array yourself","Add a Rank check before calling CopyTo"],"exampleFix":"// before\nvar dest = new double[count, 2];\ncollection.CopyTo(dest, 0);\n// after\nvar dest = new double[count];\ncollection.CopyTo(dest, 0);","handlingStrategy":"validation","validationCode":"ArgumentNullException.ThrowIfNull(dest);\nif (dest.Rank != 1) throw new ArgumentException(\"dest must be 1-D\", nameof(dest));\ncollection.CopyTo(dest, index);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always allocate copy destinations as single-dimensional arrays (T[])","In generic Array-taking helpers, assert Rank == 1 early","Prefer double[] over Array in signatures so the type system prevents this"],"tags":["wpf","collections","copyto","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"}