jstedfast/MailKit · error · ArgumentNullException

ArgumentNullException

Error message

ArgumentNullException

What it means

The FolderRenamedEventArgs(string oldName, string newName) constructor throws ArgumentNullException when either oldName or newName is null. The event args must carry both the previous and new folder names for the FolderRenamed event, so both are documented required non-null values.

Solutions

  1. Capture the folder's name before renaming so oldName is available
  2. Pass non-empty strings for both oldName and newName
  3. When raising events yourself, validate both names before constructing the args

Example fix

// before
var args = new FolderRenamedEventArgs (oldName, null);
// after
var args = new FolderRenamedEventArgs (oldName, folder.FullName);
Defensive patterns

Strategy: validation

Validate before calling

if (oldName == null || newName == null)
    throw new InvalidOperationException ("both names required");
var args = new FolderRenamedEventArgs (oldName, newName);

Type guard

bool ValidNames (string o, string n) => o != null && n != null;

Try / catch

try {
    args = new FolderRenamedEventArgs (oldName, newName);
} catch (ArgumentNullException) {
    // skip raising the event or fix the names
}

Prevention

When it happens

Trigger: Constructing FolderRenamedEventArgs with a null oldName or newName — e.g. raising the renamed event manually where one of the names was not tracked.

Common situations: Custom IMAP session implementations raising MailKit events; unit tests building event args; code paths where the old name was never captured before renaming.

Related errors


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

Appendix: source

Thrown at MailKit/FolderRenamedEventArgs.cs:54

	public class FolderRenamedEventArgs : EventArgs
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="T:MailKit.FolderRenamedEventArgs"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="FolderRenamedEventArgs"/>.
		/// </remarks>
		/// <param name="oldName">The old name of the folder.</param>
		/// <param name="newName">The new name of the folder.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="oldName"/> is <see langword="null" />.</para>
		/// <para>-or-</para>
		/// <para><paramref name="newName"/> is <see langword="null" />.</para>
		/// </exception>
		public FolderRenamedEventArgs (string oldName, string newName)
		{
			if (oldName == null)
				throw new ArgumentNullException (nameof (oldName));

			if (newName == null)
				throw new ArgumentNullException (nameof (newName));

			OldName = oldName;
			NewName = newName;
		}

		/// <summary>
		/// The old name of the folder.
		/// </summary>
		/// <remarks>
		/// The old name of the folder.
		/// </remarks>
		/// <value>The old name.</value>
		public string OldName {
			get; private set;
		}

View on GitHub (pinned to 9d3859a785)