{"record":{"id":"dfdf9145c7d30d4c","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-options","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'options')","messagePattern":"Value cannot be null\\. \\(Parameter 'options'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolder.cs","lineNumber":3296,"sourceCode":"\t\t/// <exception cref=\"ImapProtocolException\">\n\t\t/// The server's response contained unexpected tokens.\n\t\t/// </exception>\n\t\t/// <exception cref=\"ImapCommandException\">\n\t\t/// The server replied with a NO or BAD response.\n\t\t/// </exception>\n\t\tpublic override async Task<string?> GetMetadataAsync (MetadataTag tag, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tvar ic = QueueGetMetadataCommand (tag, cancellationToken);\n\n\t\t\tawait Engine.RunAsync (ic).ConfigureAwait (false);\n\n\t\t\treturn ProcessGetMetadataResponse (ic, tag);\n\t\t}\n\n\t\tImapCommand? QueueGetMetadataCommand (MetadataOptions options, IEnumerable<MetadataTag> tags, 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 (tags == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (tags));\n\n\t\t\tCheckState (false, false);\n\n\t\t\tif ((Engine.Capabilities & ImapCapabilities.Metadata) == 0)\n\t\t\t\tthrow new NotSupportedException (\"The IMAP server does not support the METADATA extension.\");\n\n\t\t\tvar command = new StringBuilder (\"GETMETADATA %F\");\n\t\t\tvar args = new List<object> ();\n\t\t\tbool hasOptions = false;\n\n\t\t\tif (options.MaxSize.HasValue || options.Depth != 0) {\n\t\t\t\tcommand.Append (\" (\");\n\t\t\t\tif (options.MaxSize.HasValue) {\n\t\t\t\t\tcommand.Append (\"MAXSIZE \");\n\t\t\t\t\tcommand.Append (options.MaxSize.Value.ToString (CultureInfo.InvariantCulture));","sourceCodeStart":3278,"sourceCodeEnd":3314,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L3278-L3314","documentation":"The multi-tag QueueGetMetadataCommand validates its MetadataOptions argument and throws ArgumentNullException when it is null. MetadataOptions controls MAXSIZE/DEPTH parameters and must be an object (use a new MetadataOptions() for defaults), never null.","triggerScenarios":"Calling ImapFolder.GetMetadata(MetadataOptions, IEnumerable<MetadataTag>, CancellationToken) with null options, e.g. when a nullable options variable was never assigned.","commonSituations":"Passing null intending 'no options' instead of a default MetadataOptions instance; deserialization producing null options.","solutions":["Pass a new MetadataOptions() instead of null for default behavior","Initialize options at the call site before invoking GetMetadata","Validate options non-null at your API boundary"],"exampleFix":"// before\nvar values = folder.GetMetadata(null, tags, cancellationToken);\n// after\nvar values = folder.GetMetadata(new MetadataOptions(), tags, cancellationToken);","handlingStrategy":"validation","validationCode":"if (options == null)\n    throw new ArgumentException(\"Options are required; use new MetadataOptions()\", nameof(options));","typeGuard":"bool IsValidMetadataArgs(MetadataOptions o, IEnumerable<MetadataTag> t) => o != null && t != null;","tryCatchPattern":"try {\n    var values = folder.GetMetadata(options, tags, ct);\n} catch (ArgumentNullException ex) {\n    logger.LogError(ex, \"Invalid GetMetadata arguments: {Param}\", ex.ParamName);\n    throw;\n}","preventionTips":["Use new MetadataOptions() rather than null for default behavior","Initialize options objects with object initializers at construction","Add non-null assertions in your own wrapper layer","Review nullable reference-type warnings (NRT) that flag unassigned options"],"tags":["imap","metadata","null-argument","mailkit"],"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"}