{"record":{"id":"07c7812a3eef5677","repo":"dotnet/wpf","slug":"sr-collection-badrank-point3dcollection","errorCode":null,"errorMessage":"SR.Collection_BadRank","messagePattern":"SR\\.Collection_BadRank","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Point3DCollection.cs","lineNumber":365,"sourceCode":"        #endregion\n\n        #region ICollection\n\n        void ICollection.CopyTo(Array array, int index)\n        {\n            ReadPreamble();\n\n            ArgumentNullException.ThrowIfNull(array);\n\n            // This will not throw in the case that we are copying\n            // from an empty collection.  This is consistent with the\n            // BCL Collection implementations. (Windows 1587365)\n            ArgumentOutOfRangeException.ThrowIfNegative(index);\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(index, array.Length - _collection.Count);\n\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(SR.Collection_BadRank);\n            }\n\n            // Elsewhere in the collection we throw an AE when the type is\n            // bad so we do it here as well to be consistent\n            try\n            {\n                int count = _collection.Count;\n                for (int i = 0; i < count; i++)\n                {\n                    array.SetValue(_collection[i], index + i);\n                }\n            }\n            catch (InvalidCastException e)\n            {\n                throw new ArgumentException(SR.Format(SR.Collection_BadDestArray, this.GetType().Name), e);\n            }\n        }\n","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Point3DCollection.cs#L347-L383","documentation":"Point3DCollection.ICollection.CopyTo throws ArgumentException(SR.Collection_BadRank) when the destination array is not a one-dimensional (rank 1) array. Multi-dimensional arrays cannot be used as CopyTo targets for these generated WPF collections.","triggerScenarios":"Calling CopyTo(point3dArray2d, index) where point3dArray2d = new Point3D[a,b]; the rank check runs after index validation and throws for Rank != 1.","commonSituations":"Copying into a rectangular/multidimensional array for grid-style data layouts; interop code reusing 2D buffers.","solutions":["Use a one-dimensional array as the CopyTo destination","Copy into a flat array and manually re-index into your 2D structure","Check array.Rank == 1 before calling CopyTo"],"exampleFix":"// before\nvar grid = new Point3D[10, 10];\ncollection.CopyTo(grid, 0); // throws\n// after\nvar flat = new Point3D[collection.Count];\ncollection.CopyTo(flat, 0);\nfor (int i = 0; i < flat.Length; i++) grid[i / 10, i % 10] = flat[i];","handlingStrategy":"validation","validationCode":"if (destArray.Rank != 1) throw new ArgumentException(\"CopyTo requires a rank-1 array\");","typeGuard":"bool IsFlatArray(Array a) => a.Rank == 1;","tryCatchPattern":"try { ((ICollection)col).CopyTo(arr, 0); }\ncatch (ArgumentException ex) { /* arr.Rank != 1; use flat array */ }","preventionTips":["Always pass one-dimensional arrays to CopyTo","Check array.Rank before untyped CopyTo calls","Flatten multidimensional buffers manually"],"tags":["wpf","array","copyto"],"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"}