jstedfast/MailKit · error · ArgumentNullException

Value cannot be null. (Parameter 'entry')

Error message

Value cannot be null. (Parameter 'entry')

What it means

Validation inside the static AnnotationEntry.Parse method: the 'entry' string to parse was null. Parsing requires the annotation entry string supplied by the caller (typically obtained from an IMAP ANNOTATE response), so a null string is rejected before parsing begins.

Solutions

  1. Null-check the entry string before calling Parse
  2. Default to an empty-string handling path (Parse gives a clearer FormatException for empty input) if that suits the flow
  3. Fix the data source so the entry value is populated

Example fix

// before
var annotation = AnnotationEntry.Parse (response.Value);
// after
if (response.Value != null)
    var annotation = AnnotationEntry.Parse (response.Value);
Defensive patterns

Strategy: type-guard

Validate before calling

if (string.IsNullOrEmpty (entry))
    return null; // or skip / report

Type guard

bool CanParse (string? entry) => !string.IsNullOrEmpty (entry);

Try / catch

try {
    var annotation = AnnotationEntry.Parse (entry);
} catch (ArgumentNullException) {
    logger.LogWarning ("Skipped annotation entry: null value");
}

Prevention

When it happens

Trigger: Calling AnnotationEntry.Parse(null) or AnnotationEntry.Create(null), usually when the entry string came from an unpopulated variable, a missing dictionary value, or a null server response field.

Common situations: Reading annotation entries from config or a server response where the key was absent; deserializing data that omitted the entry field.

Related errors


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

Appendix: source

Thrown at MailKit/AnnotationEntry.cs:427

		/// <summary>
		/// Parse an annotation entry.
		/// </summary>
		/// <remarks>
		/// Parses an annotation entry.
		/// </remarks>
		/// <param name="entry">The annotation entry.</param>
		/// <returns>The parsed annotation entry.</returns>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="entry"/> is <see langword="null" />.
		/// </exception>
		/// <exception cref="System.FormatException">
		/// <paramref name="entry"/> does not conform to the annotation entry syntax.
		/// </exception>
		public static AnnotationEntry Parse (string entry)
		{
			if (entry == null)
				throw new ArgumentNullException (nameof (entry));

			if (entry.Length == 0)
				throw new FormatException ("An annotation entry cannot be empty.");

			if (entry[0] != '/' && entry[0] != '*' && entry[0] != '%')
				throw new FormatException ("An annotation entry must begin with a '/' character.");

			var scope = AnnotationScope.Both;
			int startIndex = 0, endIndex;
			string? partSpecifier = null;
			var component = 0;
			var pc = entry[0];
			string path;

			for (int i = 1; i < entry.Length; i++) {
				char c = entry[i];

				if (c >= '0' && c <= '9' && pc == '/') {

View on GitHub (pinned to 9d3859a785)