{"record":{"id":"2b75f97fd2f5997e","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-array","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'array')","messagePattern":"Value cannot be null\\. \\(Parameter 'array'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/AccessRights.cs","lineNumber":227,"sourceCode":"\t\t/// <summary>\n\t\t/// Copies all of the access rights to the specified array.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Copies all of the access rights into the array,\n\t\t/// starting at the specified array index.\n\t\t/// </remarks>\n\t\t/// <param name=\"array\">The array.</param>\n\t\t/// <param name=\"arrayIndex\">The array index.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"array\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentOutOfRangeException\">\n\t\t/// <paramref name=\"arrayIndex\"/> is out of range.\n\t\t/// </exception>\n\t\tpublic void CopyTo (AccessRight[] array, int arrayIndex)\n\t\t{\n\t\t\tif (array == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (array));\n\n\t\t\tif (arrayIndex < 0 || arrayIndex + Count > array.Length)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (arrayIndex));\n\n\t\t\tlist.CopyTo (array, arrayIndex);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Removes the specified access right.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Removes the specified access right.\n\t\t/// </remarks>\n\t\t/// <returns><see langword=\"true\" /> if the access right was removed; otherwise, <see langword=\"false\" />.</returns>\n\t\t/// <param name=\"right\">The access right.</param>\n\t\tpublic bool Remove (AccessRight right)\n\t\t{\n\t\t\treturn list.Remove (right);","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AccessRights.cs#L209-L245","documentation":"AccessRights.CopyTo(AccessRight[] array, int arrayIndex) implements ICollection copy semantics: a null destination array throws ArgumentNullException(nameof(array)) at MailKit/AccessRights.cs:227. The array is required as the destination buffer for the rights list.","triggerScenarios":"Calling accessRights.CopyTo(null, 0) — passing a null array, commonly from a method that returns an array lazily or a variable initialized to null.","commonSituations":"Serializing rights or converting an AccessRights collection to an array where the destination array construction was skipped or conditional.","solutions":["Allocate the destination array first, e.g. var arr = new AccessRight[accessRights.Count]; accessRights.CopyTo(arr, 0).","Alternatively use the collection initializer or LINQ ToArray() instead of calling CopyTo directly.","Add a null check before calling CopyTo."],"exampleFix":"// before\nAccessRight[] arr = null;\naccessRights.CopyTo(arr, 0);\n\n// after\nvar arr = new AccessRight[accessRights.Count];\naccessRights.CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"var arr = new AccessRight[accessRights.Count];\naccessRights.CopyTo(arr, 0);","typeGuard":"bool CanCopyTo(AccessRight[] arr) => arr != null;","tryCatchPattern":"try\n{\n    accessRights.CopyTo(array, 0);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"array\")\n{\n    array = new AccessRight[accessRights.Count];\n    accessRights.CopyTo(array, 0);\n}","preventionTips":["Always allocate the destination array before calling CopyTo","Prefer ToArray()/ToList() over manual CopyTo when a new collection is fine","Initialize array fields at declaration instead of leaving them null"],"tags":["argument-null","copyto","imap","mailkit"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}