jstedfast/MailKit · error · ArgumentNullException
ArgumentNullException
Error message
ArgumentNullException
What it means
The FolderNotOpenException(string folderName, FolderAccess access, string message, Exception innerException) constructor throws ArgumentNullException when folderName is null. FolderNotOpenException reports which folder was not open and with what access level, so a null folderName violates its documented contract.
Solutions
- Pass the actual folder name (e.g. folder.FullName)
- Capture the folder name before the inner try block so it is in scope when throwing
- If no name exists, use a different exception type
Example fix
// before throw new FolderNotOpenException (null, access, msg, inner); // after throw new FolderNotOpenException (folder.FullName, access, msg, inner);
Defensive patterns
Strategy: validation
Validate before calling
if (folderName == null)
throw new InvalidOperationException ("folder name required");
throw new FolderNotOpenException (folderName, access, message, innerException); Type guard
bool HasName (IMailFolder f) => f != null && f.FullName != null;
Try / catch
try {
throw new FolderNotOpenException (folderName, access, message, inner);
} catch (ArgumentNullException ex) when (ex.ParamName == "folderName") {
// rethrow with a real name
} Prevention
- Obtain the name from the IMailFolder instance (FullName) before throwing
- Check folder.IsOpen and call Open instead of hand-building this exception
- Keep the folder reference in scope in wrap-and-rethrow code
When it happens
Trigger: Constructing FolderNotOpenException with a null folderName, e.g. rethrow code where the folder reference was lost.
Common situations: Wrapping IMAP operation failures on unopened folders; application-level guard helpers that build this exception generically without the name.
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/74d9e06a469d3c6d.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/FolderNotOpenException.cs:90
#endif
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="FolderNotOpenException"/>.
/// </remarks>
/// <param name="folderName">The folder name.</param>
/// <param name="access">The minimum folder access required by the operation.</param>
/// <param name="message">The error message.</param>
/// <param name="innerException">The inner exception.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="folderName"/> is <see langword="null" />.
/// </exception>
public FolderNotOpenException (string folderName, FolderAccess access, string message, Exception innerException) : base (message, innerException)
{
if (folderName == null)
throw new ArgumentNullException (nameof (folderName));
FolderName = folderName;
FolderAccess = access;
}
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.FolderNotOpenException"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="FolderNotOpenException"/>.
/// </remarks>
/// <param name="folderName">The folder name.</param>
/// <param name="access">The minimum folder access required by the operation.</param>
/// <param name="message">The error message.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="folderName"/> is <see langword="null" />.
/// </exception>
public FolderNotOpenException (string folderName, FolderAccess access, string message) : base (message)View on GitHub (pinned to 9d3859a785)