{"record":{"id":"59a29890fb5ea1c0","repo":"dotnet/wpf","slug":"sr-tablecollectionrankmultidimnotsupported","errorCode":null,"errorMessage":"SR.TableCollectionRankMultiDimNotSupported","messagePattern":"SR\\.TableCollectionRankMultiDimNotSupported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ContentElementCollection.cs","lineNumber":69,"sourceCode":"        /// <see cref=\"ICollection.CopyTo\"/>\n        /// </summary>\n        /// <exception cref=\"ArgumentNullException\">\n        /// <see cref=\"ICollection.CopyTo\"/>\n        /// </exception>\n        /// <exception cref=\"ArgumentException\">\n        /// <see cref=\"ICollection.CopyTo\"/>\n        /// </exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        /// <see cref=\"ICollection.CopyTo\"/>\n        /// </exception>\n        /// <param name=\"array\"><see cref=\"ICollection.CopyTo\"/></param>\n        /// <param name=\"index\"><see cref=\"ICollection.CopyTo\"/></param>\n        public void CopyTo(Array array, int index)\n        {\n            ArgumentNullException.ThrowIfNull(array);\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(SR.TableCollectionRankMultiDimNotSupported);\n            }\n            if (index < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(index), SR.TableCollectionOutOfRangeNeedNonNegNum);\n            }\n            if (array.Length - index < Size)\n            {\n                throw new ArgumentException(SR.TableCollectionInvalidOffLen);\n            }\n\n            Array.Copy(Items, 0, array, index, Size);\n        }\n\n        /// <summary>\n        /// Strongly typed version of ICollection.CopyTo.\n        /// </summary>\n        /// <exception cref=\"ArgumentNullException\">\n        /// <see cref=\"ICollection.CopyTo\"/>","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ContentElementCollection.cs#L51-L87","documentation":"ContentElementCollection.CopyTo requires a single-dimensional array target; ICollection.CopyTo contract in this WPF collection only supports rank-1 arrays. Passing a multi-dimensional array (Rank != 1) throws ArgumentException with TableCollectionRankMultiDimNotSupported. It is a pre-copy argument validation failure before any elements are copied.","triggerScenarios":"Calling CopyTo (explicitly or via ICollection.CopyTo, SerializationInfo, LINQ copy helpers) on a ContentElementCollection (e.g. TableCell blocks/text elements) with a 2D array like new object[2,2].","commonSituations":"Legacy code written for APIs that accept multidimensional arrays; generic serialization helpers that allocate Array.CreateInstance(typeof(object), lengths) with multiple lengths; interop with COM or older collection code that used rectangular arrays.","solutions":["Copy into a single-dimensional array instead (e.g. ContentElement[] or object[])","Convert a multidimensional source with a manual loop flattening elements before CopyTo","If using LINQ helpers like ToArray/ToList, they already allocate rank-1 arrays — switch to those"],"exampleFix":"// before\nvar arr = new object[rows, cols];\ncollection.CopyTo(arr, 0);\n// after\nvar arr = new object[collection.Count];\ncollection.CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"if (array == null) throw new ArgumentNullException(nameof(array));\nif (array.Rank != 1) throw new ArgumentException(\"Collection supports only single-dimensional arrays\", nameof(array));\ncollection.CopyTo(array, index);","typeGuard":"bool IsRankOneArray(Array a) => a != null && a.Rank == 1;","tryCatchPattern":"try { collection.CopyTo(array, index); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"multi\"))\n{\n    var flat = new object[collection.Count];\n    collection.CopyTo(flat, index);\n}","preventionTips":["Always allocate rank-1 arrays for CopyTo targets","Use ToArray()/ToList() instead of manual CopyTo where possible","Flatten multidimensional sources manually before copying"],"tags":["wpf","argument-exception","copyto","array"],"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"}