{"record":{"id":"5ed97c03c1e712a4","repo":"JamesNK/Newtonsoft.Json","slug":"array-5ed97c","errorCode":null,"errorMessage":"array","messagePattern":"array","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JObject.cs","lineNumber":671,"sourceCode":"            RemoveAll();\n        }\n\n        bool ICollection<KeyValuePair<string, JToken?>>.Contains(KeyValuePair<string, JToken?> item)\n        {\n            JProperty? property = Property(item.Key, StringComparison.Ordinal);\n            if (property == null)\n            {\n                return false;\n            }\n\n            return (property.Value == item.Value);\n        }\n\n        void ICollection<KeyValuePair<string, JToken?>>.CopyTo(KeyValuePair<string, JToken?>[] array, int arrayIndex)\n        {\n            if (array == null)\n            {\n                throw new ArgumentNullException(nameof(array));\n            }\n            if (arrayIndex < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(arrayIndex), \"arrayIndex is less than 0.\");\n            }\n            if (arrayIndex >= array.Length && arrayIndex != 0)\n            {\n                throw new ArgumentException(\"arrayIndex is equal to or greater than the length of array.\");\n            }\n            if (Count > array.Length - arrayIndex)\n            {\n                throw new ArgumentException(\"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.\");\n            }\n\n            int index = 0;\n            foreach (JProperty property in _properties)\n            {\n                array[arrayIndex + index] = new KeyValuePair<string, JToken?>(property.Name, property.Value);","sourceCodeStart":653,"sourceCodeEnd":689,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JObject.cs#L653-L689","documentation":"ArgumentNullException thrown by JObject's ICollection<KeyValuePair<string,JToken?>>.CopyTo when the destination array is null. The check guards the destination array parameter before any copy occurs.","triggerScenarios":"Calling ((ICollection<KeyValuePair<string,JToken>>)jObject).CopyTo(null, index), or passing a null array through a generic collection-copy routine, a CollectionEditor, or LINQ-to-ICollection helpers.","commonSituations":"Generic helpers that copy ICollection contents to a caller-supplied buffer where the buffer was not allocated; binding/designer code that passes null expecting lazy allocation.","solutions":["Allocate the destination array before calling CopyTo: new KeyValuePair<string,JToken?>[jObject.Count].","Avoid CopyTo entirely and materialize via LINQ: jObject.Properties().Select(p => new KeyValuePair<string,JToken?>(p.Name, p.Value)).ToArray().","Null-check the array before dispatching in shared helpers."],"exampleFix":"// before\nvar arr = (KeyValuePair<string, JToken?>[])null;\n((ICollection<KeyValuePair<string, JToken?>>)jObject).CopyTo(arr, 0);\n\n// after\nvar arr = new KeyValuePair<string, JToken?>[jObject.Count];\n((ICollection<KeyValuePair<string, JToken?>>)jObject).CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"if (array == null) throw new ArgumentNullException(nameof(array));\n((ICollection<KeyValuePair<string, JToken?>>)jObject).CopyTo(array, arrayIndex);","typeGuard":null,"tryCatchPattern":"try { ((ICollection<KeyValuePair<string,JToken?>>)jObject).CopyTo(arr, idx); }\ncatch (ArgumentNullException) { arr = new KeyValuePair<string, JToken?>[jObject.Count]; }","preventionTips":["Always allocate the destination array before CopyTo.","Prefer LINQ ToArray()/ToList() to avoid manual buffer management.","Null-check caller-supplied buffers in shared helpers."],"tags":["newtonsoft-json","linq-to-json","jobject","copyto","null-argument"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}