dotnet/wpf · error
SR.TableCollectionRankMultiDimNotSupported
Error message
SR.TableCollectionRankMultiDimNotSupported
What it means
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.
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
Example fix
// before var arr = new object[rows, cols]; collection.CopyTo(arr, 0); // after var arr = new object[collection.Count]; collection.CopyTo(arr, 0);
Defensive patterns
Strategy: validation
Validate before calling
if (array == null) throw new ArgumentNullException(nameof(array));
if (array.Rank != 1) throw new ArgumentException("Collection supports only single-dimensional arrays", nameof(array));
collection.CopyTo(array, index); Type guard
bool IsRankOneArray(Array a) => a != null && a.Rank == 1;
Try / catch
try { collection.CopyTo(array, index); }
catch (ArgumentException ex) when (ex.Message.Contains("multi"))
{
var flat = new object[collection.Count];
collection.CopyTo(flat, index);
} Prevention
- Always allocate rank-1 arrays for CopyTo targets
- Use ToArray()/ToList() instead of manual CopyTo where possible
- Flatten multidimensional sources manually before copying
When it happens
Trigger: 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].
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength
- Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength
- Collection_CopyTo_NumberOfElementsExceedsArrayLength
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/59a29890fb5ea1c0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/ContentElementCollection.cs:69
/// <see cref="ICollection.CopyTo"/>
/// </summary>
/// <exception cref="ArgumentNullException">
/// <see cref="ICollection.CopyTo"/>
/// </exception>
/// <exception cref="ArgumentException">
/// <see cref="ICollection.CopyTo"/>
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <see cref="ICollection.CopyTo"/>
/// </exception>
/// <param name="array"><see cref="ICollection.CopyTo"/></param>
/// <param name="index"><see cref="ICollection.CopyTo"/></param>
public void CopyTo(Array array, int index)
{
ArgumentNullException.ThrowIfNull(array);
if (array.Rank != 1)
{
throw new ArgumentException(SR.TableCollectionRankMultiDimNotSupported);
}
if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index), SR.TableCollectionOutOfRangeNeedNonNegNum);
}
if (array.Length - index < Size)
{
throw new ArgumentException(SR.TableCollectionInvalidOffLen);
}
Array.Copy(Items, 0, array, index, Size);
}
/// <summary>
/// Strongly typed version of ICollection.CopyTo.
/// </summary>
/// <exception cref="ArgumentNullException">
/// <see cref="ICollection.CopyTo"/>View on GitHub (pinned to 81131a70a4)