{"record":{"id":"f47786174c390d4d","repo":"dotnet/wpf","slug":"sr-format-sr-collection-copyto-familymapcollection","errorCode":null,"errorMessage":"SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, \"index\", \"array\")","messagePattern":"SR\\.Format\\(SR\\.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, \"index\", \"array\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FamilyMapCollection.cs","lineNumber":77,"sourceCode":"        }\n\n        /// <summary>\n        /// Determines whether the FontFamily contains the specified FontFamilyMap.\n        /// </summary>\n        public bool Contains(FontFamilyMap item)\n        {\n            return FindItem(item) >= 0;\n        }\n\n        /// <summary>\n        /// Copies the contents of the list to the specified array.\n        /// </summary>\n        public void CopyTo(FontFamilyMap[] array, int index)\n        {\n            ArgumentNullException.ThrowIfNull(array);\n\n            if (index >= array.Length)\n                throw new ArgumentException(SR.Format(SR.Collection_CopyTo_IndexGreaterThanOrEqualToArrayLength, \"index\", \"array\"));\n\n            if (_count > array.Length - index)\n                throw new ArgumentException(SR.Format(SR.Collection_CopyTo_NumberOfElementsExceedsArrayLength, index, \"array\"));\n\n            if (_count != 0)\n                Array.Copy(_items, 0, array, index, _count);\n        }\n\n        void SC.ICollection.CopyTo(Array array, int index)\n        {\n            ArgumentNullException.ThrowIfNull(array);\n\n            if (array.Rank != 1)\n                throw new ArgumentException(SR.Collection_CopyTo_ArrayCannotBeMultidimensional);\n\n            Type elementType = array.GetType().GetElementType();\n            if (!elementType.IsAssignableFrom(typeof(FamilyTypeface)))\n                throw new ArgumentException(SR.Format(SR.CannotConvertType, typeof(FamilyTypeface), elementType));","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FamilyMapCollection.cs#L59-L95","documentation":"FamilyMapCollection.CopyTo(FontFamilyMap[] array, int index) throws ArgumentException when index is greater than or equal to array.Length, because there is no room for even one element at that position. This mirrors the standard ICollection.CopyTo contract.","triggerScenarios":"Calling CopyTo with an index equal to or beyond the destination array length, e.g. copying into an empty array with index 0, or reusing a stale index from a larger array.","commonSituations":"Paginated copy loops that overshoot the array end, buffers sized from a previous collection count, or passing collection Count as the index.","solutions":["Pass an index within [0, array.Length-1], typically 0 for a fresh buffer.","Size the destination array to at least index + collection.Count before copying.","Guard the call: if (index < array.Length) collection.CopyTo(array, index);"],"exampleFix":"// before\nvar maps = new FontFamilyMap[0];\nfamilyMaps.CopyTo(maps, 0);\n// after\nvar maps = new FontFamilyMap[familyMaps.Count];\nfamilyMaps.CopyTo(maps, 0);","handlingStrategy":"validation","validationCode":"if (array == null) throw new ArgumentNullException(nameof(array));\nif (index < 0 || index >= array.Length) throw new ArgumentOutOfRangeException(nameof(index));","typeGuard":null,"tryCatchPattern":"try { col.CopyTo(array, index); }\ncatch (ArgumentException ex) { log.Warn($\"CopyTo bounds: {ex.Message}\"); }","preventionTips":["Use index 0 with freshly allocated arrays","Check array.Length before choosing an index"],"tags":["wpf","fonts","collections","argument-validation"],"backgroundTag":"index-out-of-range","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"}