{"record":{"id":"b7257375eb9ec99c","repo":"dotnet/wpf","slug":"collection-copyto-indexgreaterthanorequaltoarraylength-b72573","errorCode":null,"errorMessage":"Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength","messagePattern":"Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealPoints.cs","lineNumber":123,"sourceCode":"        }\n\n        public void CopyTo(Point[] array, int arrayIndex)\n        {\n            // parameter validations\n            ArgumentNullException.ThrowIfNull(array);\n\n            if (array.Rank != 1)\n            {\n                throw new ArgumentException(\n                    SR.Collection_CopyTo_ArrayCannotBeMultidimensional, \n                    nameof(array));                \n            }\n\n            ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);\n\n            if (arrayIndex >= array.Length)\n            {\n                throw new ArgumentException(\n                    SR.Format(\n                        SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, \n                        \"arrayIndex\", \n                        \"array\"),\n                    nameof(arrayIndex));\n            }\n\n            if ((array.Length - Count - arrayIndex) < 0)\n            {\n                throw new ArgumentException(\n                    SR.Format(\n                        SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength,\n                        \"arrayIndex\",\n                        \"array\"));\n            }           \n            \n\n            // do the copying here","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealPoints.cs#L105-L141","documentation":"This entry covers ThousandthOfEmRealPoints.CopyTo throwing ArgumentException(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength) when arrayIndex >= array.Length (the source line:178 region shows the same validation as ThousandthOfEmRealDoubles:178; the multidimensional check at line 114 precedes it). It enforces the ICollection.CopyTo contract for the Point-based fixed-size metric collection.","triggerScenarios":"Calling CopyTo on ThousandthOfEmRealPoints with arrayIndex >= destination array length, e.g. CopyTo(new Point[4], 4); also throws the multidimensional error at line 114 if the destination Array has Rank != 1 (e.g. Point[,]).","commonSituations":"Off-by-one offsets into shared metric buffers; passing 2D Point arrays; reusing indices computed for a different (larger) buffer; copying glyph-origin data with stale bounds.","solutions":["Pass arrayIndex strictly less than array.Length (0 for a fresh buffer)","Use a single-dimensional Point[] with Length >= Count + arrayIndex","Pre-validate: ArgumentNullException.ThrowIfNull(dest); if (dest.Rank != 1 || index >= dest.Length) fix before calling"],"exampleFix":"// before\nvar dest = new Point[count, 2];\ncollection.CopyTo(dest, dest.Length);\n// after\nvar dest = new Point[collection.Count];\ncollection.CopyTo(dest, 0);","handlingStrategy":"validation","validationCode":"ArgumentNullException.ThrowIfNull(dest);\nif (dest.Rank != 1) throw new ArgumentException(\"dest must be 1-D\");\nif (index >= dest.Length) throw new ArgumentException(\"index out of range\");\nif (dest.Length - index < collection.Count) throw new ArgumentException(\"dest too small\");\ncollection.CopyTo(dest, index);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate all three CopyTo preconditions (null, rank, index, capacity) in one helper","Start with index 0 on fresh buffers","Keep buffer occupancy tracked so offsets stay < dest.Length"],"tags":["wpf","collections","copyto","argument-exception","points"],"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-21T21:30:21.729Z"}