{"record":{"id":"eced7692de910b81","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-response","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'response')","messagePattern":"Value cannot be null\\. \\(Parameter 'response'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/MessageSentEventArgs.cs","lineNumber":59,"sourceCode":"\t\t/// Initializes a new instance of the <see cref=\"MailKit.MessageSentEventArgs\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"MessageSentEventArgs\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"message\">The message that was just sent.</param>\n\t\t/// <param name=\"response\">The response from the server.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <para><paramref name=\"message\"/> is <see langword=\"null\" />.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"response\"/> is <see langword=\"null\" />.</para>\n\t\t/// </exception>\n\t\tpublic MessageSentEventArgs (MimeMessage message, string response)\n\t\t{\n\t\t\tif (message == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (message));\n\n\t\t\tif (response == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (response));\n\n\t\t\tMessage = message;\n\t\t\tResponse = response;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the message that was just sent.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the message that was just sent.\n\t\t/// </remarks>\n\t\t/// <value>The message.</value>\n\t\tpublic MimeMessage Message {\n\t\t\tget; private set;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the server's response.","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/MessageSentEventArgs.cs#L41-L77","documentation":"MessageSentEventArgs' constructor throws ArgumentNullException when the server `response` string is null. MailKit records the SMTP server's reply alongside the sent message, and requires a non-null (possibly empty) response string for event handlers.","triggerScenarios":"Calling `new MessageSentEventArgs(message, null)`, or a custom SmtpClient implementation that raises MessageSent with a null response because it never read the server's reply (e.g. pipelining or a mocked stream returning null).","commonSituations":"Mock SMTP streams in unit tests whose ReadLine returns null at end-of-stream; custom transports that skip reading the final server response; wrappers that pass through a null response variable.","solutions":["Pass the actual server response string, or an empty string \"\" if none is available: `new MessageSentEventArgs(message, response ?? \"\")`.","In custom SmtpClient implementations, ensure the final server reply is read before raising MessageSent.","In mocks, return a valid response line such as \"250 OK\" instead of null."],"exampleFix":"// before\nvar args = new MessageSentEventArgs(message, response);\n// after\nvar args = new MessageSentEventArgs(message, response ?? string.Empty);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(response))\n    response = string.Empty;\nvar args = new MessageSentEventArgs(message, response);","typeGuard":"bool IsValidResponse(string response) => response != null;","tryCatchPattern":"try {\n    var args = new MessageSentEventArgs(message, response);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"response\") {\n    var args = new MessageSentEventArgs(message, string.Empty);\n}","preventionTips":["Always read the server's final reply before raising MessageSent; coalesce to \"\" if unavailable.","In mock SMTP streams, return real response lines (\"250 OK\") instead of null.","Treat a null server reply as a transport failure, not a normal event."],"tags":["csharp","mailkit","argument-null","smtp"],"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"}