{"record":{"id":"71541052920fa541","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-entry","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'entry')","messagePattern":"Value cannot be null\\. \\(Parameter 'entry'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Annotation.cs","lineNumber":54,"sourceCode":"\t/// <para>For more information about annotations, see\n\t/// <a href=\"https://tools.ietf.org/html/rfc5257\">rfc5257</a>.</para>\n\t/// </remarks>\n\tpublic class Annotation\n\t{\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.Annotation\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"Annotation\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"entry\">The annotation entry.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"entry\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic Annotation (AnnotationEntry entry)\n\t\t{\n\t\t\tif (entry is null)\n\t\t\t\tthrow new ArgumentNullException (nameof (entry));\n\n\t\t\tProperties = new Dictionary<AnnotationAttribute, string?> ();\n\t\t\tEntry = entry;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the annotation tag.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the annotation tag.\n\t\t/// </remarks>\n\t\t/// <value>The annotation tag.</value>\n\t\tpublic AnnotationEntry Entry {\n\t\t\tget; private set;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the annotation properties.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Annotation.cs#L36-L72","documentation":"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.","triggerScenarios":"Calling new Annotation(null) — passing a null AnnotationEntry, typically from a failed lookup, unset variable, or a deserialized annotation list containing null elements.","commonSituations":"Setting IMAP annotations (ANNOTATE extension) where the entry (message UID + part specifier) was not resolved before construction; iterating a parsed list that includes nulls.","solutions":["Construct a valid AnnotationEntry (message index + entry specifier) and pass it to the Annotation constructor.","Fix the code that produces the AnnotationEntry so it cannot return null; filter nulls from collections before iterating.","Add a null check at the construction site and skip/log invalid annotation entries."],"exampleFix":"// before\nvar entry = ResolveEntry(uid); // may be null\nvar annotation = new Annotation(entry);\n\n// after\nvar entry = ResolveEntry(uid);\nif (entry == null)\n    throw new InvalidOperationException($\"No annotation entry for UID {uid}\");\nvar annotation = new Annotation(entry);","handlingStrategy":"validation","validationCode":"if (entry != null)\n{\n    var annotation = new Annotation(entry);\n}","typeGuard":"bool HasEntry(AnnotationEntry entry) => entry is not null;","tryCatchPattern":"try\n{\n    var annotation = new Annotation(entry);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"entry\")\n{\n    logger.LogError(\"Annotation entry unresolved\");\n}","preventionTips":["Resolve the AnnotationEntry (message/part) before constructing Annotation","Filter nulls from deserialized annotation lists before iterating","Fail early with a descriptive error when an entry cannot be resolved"],"tags":["argument-null","imap","annotation","mailkit"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}