jstedfast/MailKit · error · ArgumentException
Annotation entry paths cannot be empty.
Error message
Annotation entry paths cannot be empty.
What it means
AnnotationEntry.ValidatePath throws ArgumentException when the entry path is an empty string. IMAP annotation entry paths (RFC 5257) must start with '/' (or be a wildcard), so an empty path cannot identify any entry.
Solutions
- Validate with string.IsNullOrWhiteSpace(path) before constructing AnnotationEntry.
- Ensure the path includes at least the leading '/' (e.g. "/comment").
- Fix the producer of the empty string (trim, split, config read).
Example fix
// before
var entry = new AnnotationEntry(input, AnnotationScope.Shared);
// after
if (string.IsNullOrWhiteSpace(input))
throw new FormatException("Annotation entry path is required");
var entry = new AnnotationEntry(input, AnnotationScope.Shared); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(path))
throw new FormatException("Annotation entry path must be non-empty and start with '/'");
var entry = new AnnotationEntry(path, AnnotationScope.Shared); Type guard
bool IsValidEntryPath(string p) => !string.IsNullOrEmpty(p) && (p[0] == '/' || p == "*" || p == "%");
Try / catch
try
{
var entry = new AnnotationEntry(path, AnnotationScope.Shared);
}
catch (ArgumentException ex) when (ex.ParamName == "path")
{
// reject/repair empty path from config or input
} Prevention
- Validate entry paths at config-load time.
- Require the leading '/' in any user/config supplied path.
- Check for empty segments when parsing combined entry/attribute strings.
When it happens
Trigger: Calling `new AnnotationEntry("", scope)`, or passing an empty string produced by trimming/splitting user input or config values.
Common situations: Blank config entries for annotation paths; splitting a full annotation string (entry + attribute) and taking a segment that is empty.
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
- Annotation attribute specifiers cannot be empty.
- Value cannot be null. (Parameter 'specifier')
- Annotation attribute specifiers cannot contain '*' or '%'.
- Value cannot be null. (Parameter 'path')
- Annotation entry paths must begin with '/'.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/a04347d9b4ad02a7.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/AnnotationEntry.cs:118
/// Used to get or set a private alternate subject on a message.
/// </remarks>
public static readonly AnnotationEntry PrivateAltSubject = new AnnotationEntry ("/altsubject", AnnotationScope.Private);
/// <summary>
/// An annotation entry for a shared alternate subject on a message.
/// </summary>
/// <remarks>
/// Used to get or set a shared alternate subject on a message.
/// </remarks>
public static readonly AnnotationEntry SharedAltSubject = new AnnotationEntry ("/altsubject", AnnotationScope.Shared);
static void ValidatePath (string path)
{
if (path == null)
throw new ArgumentNullException (nameof (path));
if (path.Length == 0)
throw new ArgumentException ("Annotation entry paths cannot be empty.", nameof (path));
if (path[0] != '/' && path[0] != '*' && path[0] != '%')
throw new ArgumentException ("Annotation entry paths must begin with '/'.", nameof (path));
if (path.Length > 1 && path[1] >= '0' && path[1] <= '9')
throw new ArgumentException ("Annotation entry paths must not include a part-specifier.", nameof (path));
if (path == "*" || path == "%")
return;
char pc = path[0];
for (int i = 1; i < path.Length; i++) {
char c = path[i];
if (c > 127)
throw new ArgumentException ($"Invalid character in annotation entry path: '{c}'.", nameof (path));
View on GitHub (pinned to 9d3859a785)