jstedfast/MailKit · error · ArgumentNullException

Value cannot be null. (Parameter 'entry')

Error message

Value cannot be null. (Parameter 'entry')

What it means

The Annotation(AnnotationEntry entry) constructor binds an annotation to an IMAP ANNOTATE entry and throws ArgumentNullException(nameof(entry)) at MailKit/Annotation.cs:54 when entry is null. The entry identifies which message/part the annotation attributes apply to, so it is mandatory.

Solutions

  1. Construct a valid AnnotationEntry (message index + entry specifier) and pass it to the Annotation constructor.
  2. Fix the code that produces the AnnotationEntry so it cannot return null; filter nulls from collections before iterating.
  3. Add a null check at the construction site and skip/log invalid annotation entries.

Example fix

// before
var entry = ResolveEntry(uid); // may be null
var annotation = new Annotation(entry);

// after
var entry = ResolveEntry(uid);
if (entry == null)
    throw new InvalidOperationException($"No annotation entry for UID {uid}");
var annotation = new Annotation(entry);
Defensive patterns

Strategy: validation

Validate before calling

if (entry != null)
{
    var annotation = new Annotation(entry);
}

Type guard

bool HasEntry(AnnotationEntry entry) => entry is not null;

Try / catch

try
{
    var annotation = new Annotation(entry);
}
catch (ArgumentNullException ex) when (ex.ParamName == "entry")
{
    logger.LogError("Annotation entry unresolved");
}

Prevention

When it happens

Trigger: Calling new Annotation(null) — passing a null AnnotationEntry, typically from a failed lookup, unset variable, or a deserialized annotation list containing null elements.

Common situations: Setting IMAP annotations (ANNOTATE extension) where the entry (message UID + part specifier) was not resolved before construction; iterating a parsed list that includes nulls.

Related errors


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

Appendix: source

Thrown at MailKit/Annotation.cs:54

	/// <para>For more information about annotations, see
	/// <a href="https://tools.ietf.org/html/rfc5257">rfc5257</a>.</para>
	/// </remarks>
	public class Annotation
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.Annotation"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="Annotation"/>.
		/// </remarks>
		/// <param name="entry">The annotation entry.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="entry"/> is <see langword="null" />.
		/// </exception>
		public Annotation (AnnotationEntry entry)
		{
			if (entry is null)
				throw new ArgumentNullException (nameof (entry));

			Properties = new Dictionary<AnnotationAttribute, string?> ();
			Entry = entry;
		}

		/// <summary>
		/// Get the annotation tag.
		/// </summary>
		/// <remarks>
		/// Gets the annotation tag.
		/// </remarks>
		/// <value>The annotation tag.</value>
		public AnnotationEntry Entry {
			get; private set;
		}

		/// <summary>
		/// Get the annotation properties.

View on GitHub (pinned to 9d3859a785)