{"record":{"id":"89fe321f7187a30a","repo":"microsoft/autogen","slug":"value-cannot-be-null-parameter-array","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'array')","messagePattern":"Value cannot be null\\. \\(Parameter 'array'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Messages.cs","lineNumber":321,"sourceCode":"\n    /// <inheritdoc cref=\"ICollection{AIContent}.Clear\" />\n    public void Clear()\n    {\n        this.Content.Clear();\n    }\n\n    /// <inheritdoc cref=\"ICollection{AIContent}.Contains\" />\n    public bool Contains(AIContent item)\n    {\n        return this.Content.Any(x => x.AIContent == item);\n    }\n\n    /// <inheritdoc cref=\"ICollection{AIContent}.CopyTo\" />\n    public void CopyTo(AIContent[] array, int arrayIndex)\n    {\n        if (array == null)\n        {\n            throw new ArgumentNullException(nameof(array));\n        }\n\n        if (arrayIndex < 0 || arrayIndex >= array.Length)\n        {\n            throw new ArgumentOutOfRangeException(nameof(arrayIndex));\n        }\n\n        if (array.Length - arrayIndex < this.Content.Count)\n        {\n            throw new ArgumentException(\"The number of elements in the source is greater than the available space from arrayIndex to the end of the destination array.\");\n        }\n\n        for (var i = 0; i < this.Content.Count; i++)\n        {\n            array[arrayIndex + i] = this.Content[i].AIContent;\n        }\n    }\n","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Messages.cs#L303-L339","documentation":"Standard ICollection<AIContent>.CopyTo contract enforcement in MultiModalMessage/MultiModalData content collection. CopyTo throws ArgumentNullException(nameof(array)) when the destination array is null, before any bounds checks run.","triggerScenarios":"Calling CopyTo(null, index) on the Content collection of a MultiModalMessage, or a generic helper/BCL API (e.g. LINQ buffer copies, collection initializers) invoking CopyTo with a null array.","commonSituations":"Hand-written CopyTo calls during refactors; generic collection utilities that forward a caller-supplied array without null checks; interop layers that allocate arrays conditionally and pass null on a failed allocation path.","solutions":["Allocate the destination array with at least Content.Count elements before calling CopyTo","Null-check the array at the call site and fail with your own context-specific error","Prefer ToArray()/ToArray-then-Array.Copy or LINQ CopyTo alternatives that handle allocation for you"],"exampleFix":"// before\nAIContent[] dest = GetBuffer(); // may return null\nmsg.Content.CopyTo(dest, 0);\n// after\nAIContent[] dest = new AIContent[msg.Content.Count];\nmsg.Content.CopyTo(dest, 0);","handlingStrategy":"validation","validationCode":"ArgumentNullException.ThrowIfNull(array);\nmsg.Content.CopyTo(array, index);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always allocate the destination array yourself rather than accepting caller buffers unchecked","Use ArgumentNullException.ThrowIfNull at API boundaries","Prefer msg.Content.ToArray() over CopyTo when you just need a snapshot"],"tags":["autogen","collections","copyto","null-check","csharp"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}