jstedfast/MailKit · error · ArgumentNullException

message

Error message

message

What it means

MailKit's AuthenticatedEventArgs constructor throws ArgumentNullException when the message parameter is null. This event-args class carries the free-form server text received upon successful authentication, so a non-null string is required. It is typically thrown by library or subclass code, not by application developers.

Solutions

  1. Pass a non-null string (use string.Empty if there is no server text).
  2. Check the server-response parsing code so an empty response becomes an empty string, not null.
  3. In tests, provide a representative message string such as "Authenticated" when simulating the event.

Example fix

// before
var args = new AuthenticatedEventArgs(serverText); // serverText is null

// after
var args = new AuthenticatedEventArgs(serverText ?? string.Empty);
Defensive patterns

Strategy: validation

Validate before calling

if (message == null)
    throw new InvalidOperationException("AuthenticatedEventArgs requires a non-null message string");
var args = new AuthenticatedEventArgs(message);

Type guard

bool HasServerMessage(string message) => !string.IsNullOrEmpty(message);

Try / catch

try
{
    var args = new AuthenticatedEventArgs(message);
}
catch (ArgumentNullException ex) when (ex.ParamName == "message")
{
    logger.LogError(ex, "Null server message for AuthenticatedEventArgs");
}

Prevention

When it happens

Trigger: Invoking new AuthenticatedEventArgs(null) — usually from custom protocol handlers, subclasses of the authentication flow, or unit tests simulating the Authenticated event with a null message.

Common situations: Writing a custom IMAP/SMTP protocol extension that raises the Authenticated event; test harnesses faking server responses where the response text variable is null; mocking frameworks passing uninitialized strings.

Related errors


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/72671e5f5dc5eb3a. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/AuthenticatedEventArgs.cs:52

	/// Some servers, such as GMail IMAP, will send some free-form text in
	/// the response to a successful login.
	/// </remarks>
	public class AuthenticatedEventArgs : EventArgs
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.AuthenticatedEventArgs"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="AuthenticatedEventArgs"/>.
		/// </remarks>
		/// <param name="message">The free-form text.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="message"/> is <see langword="null" />.
		/// </exception>
		public AuthenticatedEventArgs (string message)
		{
			if (message == null)
				throw new ArgumentNullException (nameof (message));

			Message = message;
		}

		/// <summary>
		/// Get the free-form text sent by the server.
		/// </summary>
		/// <remarks>
		/// Gets the free-form text sent by the server.
		/// </remarks>
		/// <value>The free-form text sent by the server.</value>
		public string Message {
			get; private set;
		}
	}
}

View on GitHub (pinned to 9d3859a785)