jstedfast/MailKit · error · ArgumentException

Annotation attribute specifiers cannot be empty.

Error message

Annotation attribute specifiers cannot be empty.

What it means

The AnnotationAttribute constructor throws ArgumentException when the specifier is an empty string. IMAP annotation attributes must have at least one character (e.g. "/private" or "value"), so an empty specifier is invalid.

Solutions

  1. Check string.IsNullOrWhiteSpace(specifier) before constructing AnnotationAttribute.
  2. Validate the full specifier format (e.g. "/private", "/shared", "value.privacy") before construction.
  3. Correct whatever produced the empty string (split, trim, config read).

Example fix

// before
var attr = new AnnotationAttribute(userInput.Trim());
// after
var trimmed = userInput.Trim();
if (trimmed.Length == 0)
    throw new FormatException("Annotation attribute specifier is required");
var attr = new AnnotationAttribute(trimmed);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(specifier))
    throw new InvalidOperationException("Annotation attribute specifier must be non-empty");
var attr = new AnnotationAttribute(specifier);

Type guard

bool IsValidSpecifier(string s) => !string.IsNullOrEmpty(s) && s.IndexOfAny(new[] {'*','%'}) == -1;

Try / catch

try
{
    var attr = new AnnotationAttribute(specifier);
}
catch (ArgumentException ex) when (ex.ParamName == "specifier")
{
    // log and use a corrected/default specifier
}

Prevention

When it happens

Trigger: Calling `new AnnotationAttribute("")` directly, or passing the result of a substring/split operation that produced an empty string (e.g. specifier.Split('/')[1] when the string has no second segment).

Common situations: Parsing attribute names from a settings file or user input where the value is blank; trimming a specifier down to nothing; splitting strings without guarding for missing segments.

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


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/1fe229f5ddf9762c. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/AnnotationAttribute.cs:120

		/// Initializes a new instance of the <see cref="MailKit.AnnotationAttribute"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="AnnotationAttribute"/>.
		/// </remarks>
		/// <param name="specifier">The annotation attribute specifier.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="specifier"/> is <see langword="null" />.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="specifier"/> contains illegal characters.
		/// </exception>
		public AnnotationAttribute (string specifier)
		{
			if (specifier == null)
				throw new ArgumentNullException (nameof (specifier));

			if (specifier.Length == 0)
				throw new ArgumentException ("Annotation attribute specifiers cannot be empty.", nameof (specifier));

			// TODO: improve validation
			if (specifier.IndexOfAny (Wildcards) != -1)
				throw new ArgumentException ("Annotation attribute specifiers cannot contain '*' or '%'.", nameof (specifier));

			Specifier = specifier;

			if (specifier.EndsWith (".shared", StringComparison.Ordinal)) {
				Name = specifier.Substring (0, specifier.Length - ".shared".Length);
				Scope = AnnotationScope.Shared;
			} else if (specifier.EndsWith (".priv", StringComparison.Ordinal)) {
				Name = specifier.Substring (0, specifier.Length - ".priv".Length);
				Scope = AnnotationScope.Private;
			} else {
				Scope = AnnotationScope.Both;
				Name = specifier;
			}
		}

View on GitHub (pinned to 9d3859a785)