{"record":{"id":"c09a7cdb6b131c78","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-labels","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'labels')","messagePattern":"Value cannot be null\\. \\(Parameter 'labels'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/MessageLabelsChangedEventArgs.cs","lineNumber":57,"sourceCode":"\t{\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.MessageLabelsChangedEventArgs\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"MessageLabelsChangedEventArgs\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"index\">The message index.</param>\n\t\t/// <param name=\"labels\">The message labels.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"labels\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentOutOfRangeException\">\n\t\t/// <paramref name=\"index\"/> is out of range.\n\t\t/// </exception>\n\t\tpublic MessageLabelsChangedEventArgs (int index, IList<string> labels) : base (index)\n\t\t{\n\t\t\tif (labels == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (labels));\n\n\t\t\tLabels = new ReadOnlyCollection<string> (labels);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.MessageLabelsChangedEventArgs\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"MessageLabelsChangedEventArgs\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"index\">The message index.</param>\n\t\t/// <param name=\"labels\">The message labels.</param>\n\t\t/// <param name=\"modseq\">The modification sequence value.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"labels\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentOutOfRangeException\">\n\t\t/// <paramref name=\"index\"/> is out of range.","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/MessageLabelsChangedEventArgs.cs#L39-L75","documentation":"The MessageLabelsChangedEventArgs(int index, IList<string> labels) constructor requires a non-null labels list. ArgumentNullException is thrown when labels is null; an empty list is the correct way to express 'no labels'.","triggerScenarios":"Constructing MessageLabelsChangedEventArgs with labels = null, e.g. in custom Gmail-capable folder code raising labels-changed events.","commonSituations":"Custom IMailFolder implementations or X-GM-LABELS event plumbing where the label list was never initialized before event emission.","solutions":["Pass an empty List<string> instead of null","Coalesce null label collections to an empty list before constructing the args","Fix the producer that supplies the labels so it always returns a list"],"exampleFix":"// before\nnew MessageLabelsChangedEventArgs(index, null);\n// after\nnew MessageLabelsChangedEventArgs(index, labels ?? new List<string>());","handlingStrategy":"validation","validationCode":"if (labels == null) labels = new List<string>();\nvar args = new MessageLabelsChangedEventArgs(index, labels);","typeGuard":"IList<string> NonNull(IList<string> list) => list ?? new List<string>();","tryCatchPattern":"try { args = new MessageLabelsChangedEventArgs(index, labels); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"labels\") { args = new MessageLabelsChangedEventArgs(index, new List<string>()); }","preventionTips":["Represent 'no labels' with an empty list, not null","Initialize label lists eagerly in folder wrapper state","Coalesce nullable label collections before raising events"],"tags":["mailkit","argument-validation","null","events"],"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"}