{"record":{"id":"78414dcc910db136","repo":"dotnet/wpf","slug":"sr-collection-badrank-transform3dcollection","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/Transform3DCollection.cs","lineNumber":412,"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":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Generated/Transform3DCollection.cs#L394-L430","documentation":"Transform3DCollection.CopyTo(Array array, int index) throws ArgumentException (SR.Collection_BadRank) when the destination array is not a one-dimensional array. ICollection.CopyTo only supports flat arrays because SetValue is used with a linear index.","triggerScenarios":"Passing a multidimensional array (e.g. new Transform3D[2,2]) to CopyTo with a valid index.","commonSituations":"Copying into a reusable 2D buffer; generic serialization or interop code that hands the collection a rectangular array.","solutions":["Pass a one-dimensional array, e.g. new Transform3D[collection.Count].","If you need a 2D layout, copy to a flat array first and then reshuffle manually.","Guard with array.Rank == 1 before calling CopyTo."],"exampleFix":"// before\nvar grid = new Transform3D[2, 2];\ncollection.CopyTo(grid, 0);\n// after\nvar flat = new Transform3D[collection.Count];\ncollection.CopyTo(flat, 0);","handlingStrategy":"validation","validationCode":"if (array == null) throw new ArgumentNullException(nameof(array));\nif (array.Rank != 1) throw new ArgumentException(\"Destination array must be 1-D\", nameof(array));","typeGuard":"bool IsFlatArray(Array a) => a != null && a.Rank == 1;","tryCatchPattern":"try { collection.CopyTo(arr, 0); } catch (ArgumentException) { /* recreate as 1-D array and retry */ }","preventionTips":["Always allocate new T[collection.Count] for CopyTo targets","Check Array.Rank before any ICollection.CopyTo call","Prefer the generic CopyTo overload"],"tags":["wpf","collection","copyto","array-rank"],"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"}