{"record":{"id":"d080310d90f00b46","repo":"jstedfast/MailKit","slug":"argumentnullexception-foldernotfoundexception","errorCode":null,"errorMessage":"ArgumentNullException","messagePattern":"ArgumentNullException","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/FolderNotFoundException.cs","lineNumber":79,"sourceCode":"\t\t}\n#endif\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.FolderNotFoundException\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"FolderNotFoundException\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"message\">The error message.</param>\n\t\t/// <param name=\"folderName\">The name of the folder.</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 FolderNotFoundException (string message, string folderName, 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}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.FolderNotFoundException\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"FolderNotFoundException\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"message\">The error message.</param>\n\t\t/// <param name=\"folderName\">The name of the folder.</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 FolderNotFoundException (string message, string folderName) : base (message)\n\t\t{\n\t\t\tif (folderName == null)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/FolderNotFoundException.cs#L61-L97","documentation":"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.","triggerScenarios":"Constructing FolderNotFoundException with (message, null, innerException) — e.g. rethrowing code that lost the folder name variable.","commonSituations":"Wrapping lower-level IO/IMAP errors where the folder name was not captured; logging helpers building exceptions generically; tests of exception constructors.","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"],"exampleFix":"// before\nthrow new FolderNotFoundException (msg, null, inner);\n// after\nthrow new FolderNotFoundException (msg, folder?.Path ?? string.Empty, inner);","handlingStrategy":"validation","validationCode":"if (folderName == null)\n    throw new InvalidOperationException (\"folder name required\");\nthrow new FolderNotFoundException (message, folderName, innerException);","typeGuard":"bool HasName (IMailFolder f) => f != null && f.FullName != null;","tryCatchPattern":"try {\n    throw new FolderNotFoundException (message, folderName, inner);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"folderName\") {\n    // supply a real name and rethrow\n}","preventionTips":["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"],"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"}