{"record":{"id":"dc16593b141dfab8","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-annotations","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'annotations')","messagePattern":"Value cannot be null\\. \\(Parameter 'annotations'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationsChangedEventArgs.cs","lineNumber":55,"sourceCode":"\t/// Event args used when an annotation changes.\n\t/// </remarks>\n\tpublic class AnnotationsChangedEventArgs : MessageEventArgs\n\t{\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"T:MailKit.AnnotationsChangedEventArgs\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"AnnotationsChangedEventArgs\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"index\">The message index.</param>\n\t\t/// <param name=\"annotations\">The annotations that changed.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"annotations\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic AnnotationsChangedEventArgs (int index, IEnumerable<Annotation> annotations) : base (index)\n\t\t{\n\t\t\tif (annotations == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (annotations));\n\n\t\t\tAnnotations = new ReadOnlyCollection<Annotation> (annotations.ToArray ());\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the annotations that changed.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the annotations that changed.\n\t\t/// </remarks>\n\t\t/// <value>The annotation.</value>\n\t\tpublic IList<Annotation> Annotations {\n\t\t\tget; internal set;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Gets the updated mod-sequence value of the message, if available.\n\t\t/// </summary>","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationsChangedEventArgs.cs#L37-L73","documentation":"The AnnotationsChangedEventArgs constructor requires a non-null collection of changed annotations. Passing null throws ArgumentNullException naming the 'annotations' parameter, because the event args must wrap a concrete read-only list.","triggerScenarios":"Constructing new AnnotationsChangedEventArgs (index, null) when raising a folder annotations-changed event or in tests.","commonSituations":"Custom IMailFolder implementations raising the AnnotationsChanged event without annotation data, unit tests passing null for convenience.","solutions":["Pass an empty collection (e.g. Array.Empty<Annotation>()) instead of null when no annotations changed","Guard the call site with a null check and substitute a default empty list","If annotations are unknown, do not raise the event"],"exampleFix":"// before\nnew AnnotationsChangedEventArgs (0, null);\n// after\nnew AnnotationsChangedEventArgs (0, Array.Empty<Annotation> ());","handlingStrategy":"type-guard","validationCode":"if (annotations == null) annotations = Array.Empty<Annotation> ();","typeGuard":"bool HasAnnotations (IEnumerable<Annotation> annotations) => annotations != null;","tryCatchPattern":"try { var args = new AnnotationsChangedEventArgs (index, annotations); }\ncatch (ArgumentNullException) { args = new AnnotationsChangedEventArgs (index, Array.Empty<Annotation> ()); }","preventionTips":["Default to empty collections instead of null","Null-check event payload before raising events","Use '?? Array.Empty<Annotation>()' at construction sites"],"tags":["null-argument","eventargs","imap-annotations"],"backgroundTag":"null-argument","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}