dotnet/wpf · error · ArgumentException
Collection_CopyTo_ArrayCannotBeMultidimensional
Error message
Collection_CopyTo_ArrayCannotBeMultidimensional
What it means
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.
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
Example fix
// before var dest = new double[count, 2]; collection.CopyTo(dest, 0); // after var dest = new double[count]; collection.CopyTo(dest, 0);
Defensive patterns
Strategy: validation
Validate before calling
ArgumentNullException.ThrowIfNull(dest);
if (dest.Rank != 1) throw new ArgumentException("dest must be 1-D", nameof(dest));
collection.CopyTo(dest, index); Prevention
- 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
When it happens
Trigger: Calling CopyTo (or casting the collection to ICollection/ICollection<double> and calling CopyTo) with a multidimensional array such as double[,] as the destination.
Common situations: Passing a 2D array declared for grid-like storage to CopyTo; generic copy helpers that take Array instead of double[].
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_IndexGreaterThanOrEqualToArrayLength
- Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength
- Collection_CopyTo_NumberOfElementsExceedsArrayLength
- SR.Collection_BadRank
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5e835b81ee41ce9b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealDoubles.cs:169
{
_doubleList[i] = 0;
}
}
}
public bool Contains(double item)
{
return IndexOf(item) >= 0;
}
public void CopyTo(double[] array, int arrayIndex)
{
// parameter validations
ArgumentNullException.ThrowIfNull(array);
if (array.Rank != 1)
{
throw new ArgumentException(
SR.Collection_CopyTo_ArrayCannotBeMultidimensional,
nameof(array));
}
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
if (arrayIndex >= array.Length)
{
throw new ArgumentException(
SR.Format(
SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength,
"arrayIndex",
"array"),
nameof(arrayIndex));
}
if ((array.Length - Count - arrayIndex) < 0)
{View on GitHub (pinned to 81131a70a4)