jstedfast/MailKit · error · ArgumentNullException

Value cannot be null. (Parameter 'path')

Error message

Value cannot be null. (Parameter 'path')

What it means

AnnotationEntry.ValidatePath throws ArgumentNullException when the annotation entry path is null. Every IMAP annotation entry must be identified by a path such as "/comment", so a null path is rejected by the AnnotationEntry constructors.

Solutions

  1. Check the path for null before calling any AnnotationEntry constructor.
  2. Fix the data source so it always provides an entry path.
  3. Coalesce to a valid default path only if semantically appropriate.

Example fix

// before
var entry = new AnnotationEntry(config["Entry"], AnnotationScope.Shared);
// after
var path = config["Entry"];
if (path == null)
    throw new InvalidOperationException("Annotation entry path not configured");
var entry = new AnnotationEntry(path, AnnotationScope.Shared);
Defensive patterns

Strategy: validation

Validate before calling

if (path == null)
    throw new InvalidOperationException("Annotation entry path is required");
var entry = new AnnotationEntry(path, AnnotationScope.Shared);

Type guard

bool IsValidEntryPath(string p) => p != null && p.Length > 0 && (p[0] == '/' || p == "*" || p == "%");

Try / catch

try
{
    var entry = new AnnotationEntry(path, AnnotationScope.Shared);
}
catch (ArgumentNullException)
{
    // path was null — supply a valid path or abort
}

Prevention

When it happens

Trigger: Calling a AnnotationEntry constructor or static field-style factory with `new AnnotationEntry(null, scope)` or with a null value returned from a lookup.

Common situations: Reading entry names from config or parsed IMAP responses where the value is missing; nullable variables passed directly into the constructor.

Related errors


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

Appendix: source

Thrown at MailKit/AnnotationEntry.cs:115

		/// An annotation entry for a private alternate subject on a message.
		/// </summary>
		/// <remarks>
		/// 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];

View on GitHub (pinned to 9d3859a785)