{"record":{"id":"9088f6f6243f5b53","repo":"jstedfast/MailKit","slug":"a-metadata-tag-identifier-cannot-be-empty","errorCode":null,"errorMessage":"A metadata tag identifier cannot be empty.","messagePattern":"A metadata tag identifier cannot be empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/MetadataTag.cs","lineNumber":91,"sourceCode":"\t\t/// Initializes a new instance of the <see cref=\"MailKit.MetadataTag\"/> struct.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"MetadataTag\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"id\">The metadata tag identifier.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"id\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentException\">\n\t\t/// <paramref name=\"id\"/> is an empty string.\n\t\t/// </exception>\n\t\tpublic MetadataTag (string id)\n\t\t{\n\t\t\tif (id == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (id));\n\n\t\t\tif (id.Length == 0)\n\t\t\t\tthrow new ArgumentException (\"A metadata tag identifier cannot be empty.\");\n\n\t\t\tId = id;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the metadata tag identifier.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the metadata tag identifier.\n\t\t/// </remarks>\n\t\t/// <value>The metadata tag identifier.</value>\n\t\tpublic string Id {\n\t\t\tget; private set;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Determine whether the specified <see cref=\"System.Object\"/> is equal to the current <see cref=\"MailKit.MetadataTag\"/>.\n\t\t/// </summary>","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/MetadataTag.cs#L73-L109","documentation":"The MetadataTag(string id) constructor rejects an empty identifier because IMAP metadata tags (RFC 5464 entries like \"/private/comment\") must be non-empty strings. Null is rejected separately with ArgumentNullException.","triggerScenarios":"Calling `new MetadataTag(\"\")` or `new MetadataTag(someString)` where someString came from an empty config value, a split() result, or an uninitialized variable.","commonSituations":"Reading metadata tag names from user input or configuration files that are blank; parsing annotation names from server responses with a delimiter that yields empty tokens.","solutions":["Pass a non-empty tag id such as \"/private/comment\" or \"/shared/vendor/vendor.example.key\"","Trim and validate the source string before constructing the MetadataTag","Fix the config/input source that produced the empty identifier"],"exampleFix":"// before\nvar tag = new MetadataTag(configEntry.Name); // Name may be \"\"\n// after\nif (string.IsNullOrWhiteSpace(configEntry.Name))\n\tthrow new InvalidOperationException(\"Metadata tag name is not configured.\");\nvar tag = new MetadataTag(configEntry.Name.Trim());","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(id))\n\tthrow new ArgumentException(\"Metadata tag id must be non-empty.\", nameof(id));","typeGuard":"bool IsValidMetadataTagId(string id) => !string.IsNullOrWhiteSpace(id);","tryCatchPattern":"try {\n\tvar tag = new MetadataTag(id);\n} catch (ArgumentException) {\n\t// skip or log the invalid tag id\n}","preventionTips":["Trim and check string.IsNullOrWhiteSpace on ids from config or user input","Keep metadata tag constants in code rather than free-form config","Validate parsed token lists for empty entries before use"],"tags":["argument-validation","mailkit","metadata","empty-string"],"backgroundTag":"empty-required-field","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"}