{"record":{"id":"3849a747ceac4a6a","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-tags","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'tags')","messagePattern":"Value cannot be null\\. \\(Parameter 'tags'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolder.cs","lineNumber":3299,"sourceCode":"\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));\n\t\t\t\t\tcommand.Append (' ');\n\t\t\t\t}\n\t\t\t\tif (options.Depth > 0) {","sourceCodeStart":3281,"sourceCodeEnd":3317,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L3281-L3317","documentation":"The multi-tag QueueGetMetadataCommand throws ArgumentNullException when the tags collection is null. At least one metadata tag must be requested for GETMETADATA, so a null enumeration is rejected immediately with the parameter name.","triggerScenarios":"Calling ImapFolder.GetMetadata(MetadataOptions, IEnumerable<MetadataTag>, CancellationToken) with a null tags argument (uninitialized list, null return from a helper).","commonSituations":"Building the tag list conditionally and forgetting to default it; passing a null result of a config lookup straight into GetMetadata.","solutions":["Pass a non-empty collection of MetadataTag values (an empty list is fine; null is not)","Coalesce null to an empty list: tags ?? Enumerable.Empty<MetadataTag>()","Validate the collection before calling"],"exampleFix":"// before\nList<MetadataTag> tags = BuildTags(); // may return null\nfolder.GetMetadata(options, tags, ct);\n// after\nvar tags = BuildTags() ?? new List<MetadataTag>();\nfolder.GetMetadata(options, tags, ct);","handlingStrategy":"validation","validationCode":"if (tags == null || tags.Any(t => t == null))\n    throw new ArgumentException(\"Tags collection must be non-null with valid tags\", nameof(tags));","typeGuard":"bool HasTags(IEnumerable<MetadataTag> t) => t != null;","tryCatchPattern":"try {\n    var values = folder.GetMetadata(options, tags, ct);\n} catch (ArgumentNullException ex) {\n    logger.LogError(ex, \"Null tags passed to GetMetadata\");\n    throw;\n}","preventionTips":["Coalesce nullable tag lists: tags ?? Array.Empty<MetadataTag>()","Ensure list-building helpers never return null (return empty collections)","Enable nullable reference types to catch uninitialized collections at compile time","Write boundary tests passing null collections"],"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"}