jstedfast/MailKit · error · ArgumentException
A metadata tag identifier cannot be empty.
Error message
A metadata tag identifier cannot be empty.
What it means
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.
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
Example fix
// before
var tag = new MetadataTag(configEntry.Name); // Name may be ""
// after
if (string.IsNullOrWhiteSpace(configEntry.Name))
throw new InvalidOperationException("Metadata tag name is not configured.");
var tag = new MetadataTag(configEntry.Name.Trim()); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(id))
throw new ArgumentException("Metadata tag id must be non-empty.", nameof(id)); Type guard
bool IsValidMetadataTagId(string id) => !string.IsNullOrWhiteSpace(id);
Try / catch
try {
var tag = new MetadataTag(id);
} catch (ArgumentException) {
// skip or log the invalid tag id
} Prevention
- 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
When it happens
Trigger: Calling `new MetadataTag("")` or `new MetadataTag(someString)` where someString came from an empty config value, a split() result, or an uninitialized variable.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- The host name cannot be empty.
- The keyword cannot be an empty string.
- Cannot search for null or empty keywords.
- Cannot search an empty header field name.
- Annotation attribute specifiers cannot be empty.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/9088f6f6243f5b53.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/MetadataTag.cs:91
/// Initializes a new instance of the <see cref="MailKit.MetadataTag"/> struct.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MetadataTag"/>.
/// </remarks>
/// <param name="id">The metadata tag identifier.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="id"/> is <see langword="null" />.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="id"/> is an empty string.
/// </exception>
public MetadataTag (string id)
{
if (id == null)
throw new ArgumentNullException (nameof (id));
if (id.Length == 0)
throw new ArgumentException ("A metadata tag identifier cannot be empty.");
Id = id;
}
/// <summary>
/// Get the metadata tag identifier.
/// </summary>
/// <remarks>
/// Gets the metadata tag identifier.
/// </remarks>
/// <value>The metadata tag identifier.</value>
public string Id {
get; private set;
}
/// <summary>
/// Determine whether the specified <see cref="System.Object"/> is equal to the current <see cref="MailKit.MetadataTag"/>.
/// </summary>View on GitHub (pinned to 9d3859a785)