{"record":{"id":"7fbf1dcd0a5eb9c4","repo":"XINCGer/Unity3DTraining","slug":"not-enough-space-in-the-array","errorCode":null,"errorMessage":"Not enough space in the array","messagePattern":"Not enough space in the array","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Collections/MapField.cs","lineNumber":720,"sourceCode":"            public void Clear()\n            {\n                throw new NotSupportedException();\n            }\n\n            public bool Contains(T item)\n            {\n                return containsCheck(item);\n            }\n\n            public void CopyTo(T[] array, int arrayIndex)\n            {\n                if (arrayIndex < 0)\n                {\n                    throw new ArgumentOutOfRangeException(\"arrayIndex\");\n                }\n                if (arrayIndex + Count >= array.Length)\n                {\n                    throw new ArgumentException(\"Not enough space in the array\", \"array\");\n                }\n                foreach (var item in this)\n                {\n                    array[arrayIndex++] = item;\n                }\n            }\n\n            public IEnumerator<T> GetEnumerator()\n            {\n                return parent.list.Select(projection).GetEnumerator();\n            }\n\n            public bool Remove(T item)\n            {\n                throw new NotSupportedException();\n            }\n\n            IEnumerator IEnumerable.GetEnumerator()","sourceCodeStart":702,"sourceCodeEnd":738,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/Collections/MapField.cs#L702-L738","documentation":"MapView.CopyTo throws ArgumentException when the target array cannot hold all elements from the given start index: the check arrayIndex + Count >= array.Length rejects cases with insufficient (or exactly tight) space.","triggerScenarios":"mapField.Keys.CopyTo(smallArray, idx) where idx + Count >= smallArray.Length, e.g. copying a 10-element Values view into an 8-element array or an exact-fit array at a nonzero offset.","commonSituations":"Reusing stale buffers after the map grew; assuming Keys/Values counts match a previously sized array; off-by-one sizing that the >= check rejects even for exact fits.","solutions":["Size the array as arrayIndex + Count (plus slack) before CopyTo","Use ToArray()/ToList() on the view instead of manual CopyTo","Re-check mapField.Count at copy time; the map may have changed since the buffer was sized","Account for the >= (not >) check: allocate strictly more than index+Count"],"exampleFix":"// before\nvar arr = new byte[mapField.Count];\nmapField.Values.CopyTo(arr, 0); // may throw if count changed\n// after\nvar arr = new T[mapField.Count + 1];\nmapField.Values.CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"if (arr.Length - arrayIndex <= view.Count) arr = new T[arrayIndex + view.Count + 1];","typeGuard":null,"tryCatchPattern":"try { view.CopyTo(arr, idx); } catch (ArgumentException) { arr = new T[view.Count + idx + 1]; view.CopyTo(arr, idx); }","preventionTips":["Size buffers as index + Count + slack","Re-read Count immediately before CopyTo","Prefer ToArray()/ToList() over fixed buffers"],"tags":["protobuf","csharp","array-size"],"backgroundTag":"invalid-argument-value","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}