{"record":{"id":"74d9e06a469d3c6d","repo":"jstedfast/MailKit","slug":"argumentnullexception-foldernotopenexception","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/FolderNotOpenException.cs","lineNumber":90,"sourceCode":"#endif\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.FolderNotOpenException\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"FolderNotOpenException\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"folderName\">The folder name.</param>\n\t\t/// <param name=\"access\">The minimum folder access required by the operation.</param>\n\t\t/// <param name=\"message\">The error message.</param>\n\t\t/// <param name=\"innerException\">The inner exception.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"folderName\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic FolderNotOpenException (string folderName, FolderAccess access, string message, Exception innerException) : base (message, innerException)\n\t\t{\n\t\t\tif (folderName == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (folderName));\n\n\t\t\tFolderName = folderName;\n\t\t\tFolderAccess = access;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.FolderNotOpenException\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"FolderNotOpenException\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"folderName\">The folder name.</param>\n\t\t/// <param name=\"access\">The minimum folder access required by the operation.</param>\n\t\t/// <param name=\"message\">The error message.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"folderName\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic FolderNotOpenException (string folderName, FolderAccess access, string message) : base (message)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/FolderNotOpenException.cs#L72-L108","documentation":"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.","triggerScenarios":"Constructing FolderNotOpenException with a null folderName, e.g. rethrow code where the folder reference was lost.","commonSituations":"Wrapping IMAP operation failures on unopened folders; application-level guard helpers that build this exception generically without the name.","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"],"exampleFix":"// before\nthrow new FolderNotOpenException (null, access, msg, inner);\n// after\nthrow new FolderNotOpenException (folder.FullName, access, msg, inner);","handlingStrategy":"validation","validationCode":"if (folderName == null)\n    throw new InvalidOperationException (\"folder name required\");\nthrow new FolderNotOpenException (folderName, access, message, innerException);","typeGuard":"bool HasName (IMailFolder f) => f != null && f.FullName != null;","tryCatchPattern":"try {\n    throw new FolderNotOpenException (folderName, access, message, inner);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"folderName\") {\n    // rethrow with a real name\n}","preventionTips":["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"],"tags":["csharp","mailkit","argument-null","exception-constructor"],"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"}