dotnet/wpf · error · ArgumentException

Collection_CopyTo_ArrayCannotBeMultidimensional

Error message

Collection_CopyTo_ArrayCannotBeMultidimensional

What it means

ThousandthOfEmRealPoints.CopyTo throws ArgumentException(SR.Collection_CopyTo_ArrayCannotBeMultidimensional) when the destination Array has Rank != 1. As a fixed-size Point collection implementing ICollection, it only supports single-dimensional destinations per the standard .NET contract.

Solutions

  1. Pass a single-dimensional Point[] as destination
  2. Copy into a flat Point[] then map into your 2D structure yourself
  3. Pre-check array.Rank == 1 before calling CopyTo

Example fix

// before
var dest = new Point[count, 2];
collection.CopyTo(dest, 0);
// after
var dest = new Point[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

When it happens

Trigger: Calling CopyTo with a multidimensional destination such as Point[,], directly or through ICollection/ICollection<Point> casts.

Common situations: Storing glyph origins in 2D grids; generic Array-taking copy helpers; translating code that assumed jagged/dimensional array support.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/4d0d7506fc1d1d17. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealPoints.cs:114

        public void Clear()
        {
            _xArray.Clear();
            _yArray.Clear();
        }

        public bool Contains(Point item)
        {
            return IndexOf(item) >= 0;
        }

        public void CopyTo(Point[] 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)