{"record":{"id":"72c8c7b8f95f0771","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-request","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'request')","messagePattern":"Value cannot be null\\. \\(Parameter 'request'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolder.cs","lineNumber":4421,"sourceCode":"\t\t\tformat.NewLineFormat = NewLineFormat.Dos;\n\t\t\tformat.EnsureNewLine = true;\n\n\t\t\tif ((Engine.Capabilities & ImapCapabilities.UTF8Only) == ImapCapabilities.UTF8Only)\n\t\t\t\tformat.International = true;\n\n\t\t\tif (format.International && !Engine.UTF8Enabled)\n\t\t\t\tthrow new InvalidOperationException (\"The UTF8 extension has not been enabled.\");\n\n\t\t\treturn format;\n\t\t}\n\n\t\tImapCommand QueueAppendCommand (FormatOptions options, IAppendRequest request, CancellationToken cancellationToken)\n\t\t{\n\t\t\tif (options == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (options));\n\n\t\t\tif (request == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (request));\n\n\t\t\tCheckState (false, false);\n\n\t\t\tvar format = CreateAppendOptions (options);\n\n\t\t\tif (request.Annotations != null && request.Annotations.Count > 0 && (Engine.Capabilities & ImapCapabilities.Annotate) == 0)\n\t\t\t\tthrow new NotSupportedException (\"The IMAP server does not support annotations.\");\n\n\t\t\tint numKeywords = request.Keywords != null ? request.Keywords.Count : 0;\n\t\t\tvar builder = new StringBuilder (\"APPEND %F \");\n\t\t\tvar list = new List<object> {\n\t\t\t\tthis\n\t\t\t};\n\n\t\t\tif ((request.Flags & SettableFlags) != 0 || numKeywords > 0) {\n\t\t\t\tImapUtils.FormatFlagsList (builder, request.Flags, numKeywords);\n\t\t\t\tbuilder.Append (' ');\n\t\t\t}","sourceCodeStart":4403,"sourceCodeEnd":4439,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L4403-L4439","documentation":"QueueAppendCommand requires an IAppendRequest describing the message to APPEND; a null request throws ArgumentNullException. The request carries the message stream, flags, keywords, and optional annotations.","triggerScenarios":"Calling folder.Append(options, null) or AppendAsync with a null request; building the request in a helper that returns null on failure.","commonSituations":"Conditional upload logic that skips request construction; a factory method returning null instead of throwing; refactoring where the request variable was lost.","solutions":["Always construct an AppendRequest (with a message stream) before calling Append.","Null-check the result of any request-building helper before passing it.","Throw early in your own builder rather than returning null."],"exampleFix":"// before\nvar request = BuildRequest (message); // may return null\nfolder.Append (options, request);\n// after\nvar request = BuildRequest (message) ?? throw new InvalidOperationException (\"failed to build append request\");\nfolder.Append (options, request);","handlingStrategy":"validation","validationCode":"if (request == null) throw new InvalidOperationException (\"AppendRequest must be constructed with a message stream before Append\");","typeGuard":"bool IsValidRequest (IAppendRequest r) => r != null && r.Message != null;","tryCatchPattern":"try { folder.Append (options, request); } catch (ArgumentNullException ex) when (ex.ParamName == \"request\") { /* rebuild request */ }","preventionTips":["Construct the AppendRequest immediately before the Append call","Make request builders throw on failure instead of returning null","Validate request.Message stream is open and positioned correctly"],"tags":["imap","mailkit","null-argument","append"],"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"}