{"record":{"id":"bcb9e17820d9cfb9","repo":"dotnetcore/CAP","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":"src/DotNetCore.CAP.Dashboard/CircularBuffer.cs","lineNumber":160,"sourceCode":"        }\n\n        _items[itemIndex] = item;\n    }\n\n    public void Clear()\n    {\n        _firstIndex = 0;\n        Count = 0;\n    }\n\n    public bool Contains(T item)\n    {\n        throw new NotImplementedException();\n    }\n\n    public void CopyTo(T[] array, int arrayIndex)\n    {\n        if (array == null) throw new ArgumentNullException(nameof(array));\n\n        if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex));\n\n        if (Count > array.Length - arrayIndex) throw new ArgumentException(\"arrayIndex\");\n\n        // Iterate through the buffer in correct order.\n        foreach (var item in this)\n        {\n            array[arrayIndex++] = item;\n        }\n    }\n\n    public bool Remove(T item)\n    {\n        throw new NotImplementedException();\n    }\n\n    #endregion","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.Dashboard/CircularBuffer.cs#L142-L178","documentation":"CircularBuffer<T>.CopyTo validates its arguments and throws ArgumentNullException(\"Value cannot be null. (Parameter 'array')\") when the destination array is null. This is a standard guard before copying buffer contents into the array. Reaching it usually means the caller computed a null destination, e.g. ToArray-like code on an empty/incorrectly sized buffer.","triggerScenarios":"Passing null as the array argument to CopyTo, e.g. buffer.CopyTo(null, 0), or an indirect call from helper code (ToArray) that allocates the destination incorrectly.","commonSituations":"A factory or cache returning a null array on failure, uninitialized fields meant to hold the destination buffer, or deserialization yielding null before CopyTo is called.","solutions":["Ensure the destination array is allocated with new T[Count] (or larger) before calling CopyTo.","Add a null/empty check at the call site and skip the copy when there is nothing to copy.","If a helper (ToArray) produced null, fix it to return Array.Empty<T>() for empty buffers."],"exampleFix":"// before\nT[] result = GetDestination(); // may be null\nbuffer.CopyTo(result, 0);\n// after\nT[] result = GetDestination() ?? new T[buffer.Count];\nbuffer.CopyTo(result, 0);","handlingStrategy":"validation","validationCode":"if (dest == null) dest = new T[buffer.Count];\nbuffer.CopyTo(dest, 0);","typeGuard":null,"tryCatchPattern":"try { buffer.CopyTo(dest, 0); }\ncatch (ArgumentNullException) { dest = new T[buffer.Count]; buffer.CopyTo(dest, 0); }","preventionTips":["Always allocate the destination with new T[buffer.Count] immediately before CopyTo","Never cache destination arrays across buffer mutations","Prefer ToArray-style helpers over manual CopyTo"],"tags":["null-argument","collection","dashboard","dotnet"],"backgroundTag":"null-argument","analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}