jstedfast/MailKit · error · ArgumentNullException
ArgumentNullException
Error message
ArgumentNullException
What it means
The FolderNotFoundException(string message, string folderName, Exception innerException) constructor throws ArgumentNullException when folderName is null. The exception object exists to carry the missing folder's name, so a null name defeats its purpose and is rejected per its documented contract.
Solutions
- Pass the actual folder name string (use string.Empty if genuinely unknown is unacceptable — prefer a real value)
- Capture the folder name at the throw site before wrapping the inner exception
- If the name is unavailable, use a different exception type such as InvalidOperationException
Example fix
// before throw new FolderNotFoundException (msg, null, inner); // after throw new FolderNotFoundException (msg, folder?.Path ?? string.Empty, inner);
Defensive patterns
Strategy: validation
Validate before calling
if (folderName == null)
throw new InvalidOperationException ("folder name required");
throw new FolderNotFoundException (message, folderName, innerException); Type guard
bool HasName (IMailFolder f) => f != null && f.FullName != null;
Try / catch
try {
throw new FolderNotFoundException (message, folderName, inner);
} catch (ArgumentNullException ex) when (ex.ParamName == "folderName") {
// supply a real name and rethrow
} Prevention
- Capture folder names at the failure site before wrapping exceptions
- Never pass null for documented non-null exception parameters
- Use the folder's FullName/Path as the canonical name
When it happens
Trigger: Constructing FolderNotFoundException with (message, null, innerException) — e.g. rethrowing code that lost the folder name variable.
Common situations: Wrapping lower-level IO/IMAP errors where the folder name was not captured; logging helpers building exceptions generically; tests of exception constructors.
Related errors
- ArgumentNullException
- ArgumentNullException
- ArgumentNullException
- Value cannot be null. (Parameter 'message')
- Value cannot be null. (Parameter 'response')
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/d080310d90f00b46.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/FolderNotFoundException.cs:79
}
#endif
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.FolderNotFoundException"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="FolderNotFoundException"/>.
/// </remarks>
/// <param name="message">The error message.</param>
/// <param name="folderName">The name of the folder.</param>
/// <param name="innerException">The inner exception.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="folderName"/> is <see langword="null" />.
/// </exception>
public FolderNotFoundException (string message, string folderName, Exception innerException) : base (message, innerException)
{
if (folderName == null)
throw new ArgumentNullException (nameof (folderName));
FolderName = folderName;
}
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.FolderNotFoundException"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="FolderNotFoundException"/>.
/// </remarks>
/// <param name="message">The error message.</param>
/// <param name="folderName">The name of the folder.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="folderName"/> is <see langword="null" />.
/// </exception>
public FolderNotFoundException (string message, string folderName) : base (message)
{
if (folderName == null)View on GitHub (pinned to 9d3859a785)