{"record":{"id":"31af0974c7d48ab9","repo":"jstedfast/MailKit","slug":"one-or-more-annotations-does-not-define-any-attributes","errorCode":null,"errorMessage":"One or more annotations does not define any attributes.","messagePattern":"One or more annotations does not define any attributes\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapUtils.cs","lineNumber":215,"sourceCode":"\t\t/// Formats a list of annotations for a STORE or APPEND command.\n\t\t/// </summary>\n\t\t/// <param name=\"command\">The command builder.</param>\n\t\t/// <param name=\"annotations\">The annotations.</param>\n\t\t/// <param name=\"args\">the argument list.</param>\n\t\t/// <param name=\"throwOnError\">Throw an exception if there are any annotations without properties.</param>\n\t\tpublic static void FormatAnnotations (StringBuilder command, IList<Annotation> annotations, List<object> args, bool throwOnError)\n\t\t{\n\t\t\tint length = command.Length;\n\t\t\tint added = 0;\n\n\t\t\tcommand.Append (\"ANNOTATION (\");\n\n\t\t\tfor (int i = 0; i < annotations.Count; i++) {\n\t\t\t\tvar annotation = annotations[i];\n\n\t\t\t\tif (annotation.Properties.Count == 0) {\n\t\t\t\t\tif (throwOnError)\n\t\t\t\t\t\tthrow new ArgumentException (\"One or more annotations does not define any attributes.\", nameof (annotations));\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcommand.Append (annotation.Entry);\n\t\t\t\tcommand.Append (\" (\");\n\n\t\t\t\tforeach (var property in annotation.Properties) {\n\t\t\t\t\tcommand.Append (property.Key);\n\n\t\t\t\t\tif (property.Value != null) {\n\t\t\t\t\t\tcommand.Append (\" %S \");\n\t\t\t\t\t\targs.Add (property.Value);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcommand.Append (\" NIL \");\n\t\t\t\t\t}\n\t\t\t\t}\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapUtils.cs#L197-L233","documentation":"ImapUtils.FormatAnnotations validates the annotation list before building an IMAP ANNOTATE command. If any ImapAnnotation in the collection has no Properties, the command would be malformed, so MailKit throws an ArgumentException naming the 'annotations' parameter (or silently skips the annotation when throwOnError is false).","triggerScenarios":"Calling ImapClient.StoreAsync with a store request containing annotations where the ImapAnnotation's Properties dictionary/annotation was constructed empty, e.g. new ImapAnnotation(entry) with no calls to SetProperty.","commonSituations":"Dynamically building annotations from user/config data where an empty result slips through; copying annotations from a fetched message that had none; typos that skip property population.","solutions":["Before storing, filter or check annotations: ensure every ImapAnnotation has at least one property via annotation.Properties.Count > 0.","Populate each ImapAnnotation with SetProperty(...)/properties for the entries you intend to write.","Remove empty ImapAnnotation instances from the StoreRequest/annotation collection before calling StoreAsync."],"exampleFix":"// before\nvar annotation = new ImapAnnotation(\"/comment\");\nrequest.Annotations.Add(annotation);\nawait client.Inbox.StoreAsync(request);\n\n// after\nvar annotation = new ImapAnnotation(\"/comment\");\nannotation.SetProperty(\"value.priv\", \"my comment\");\nif (annotation.Properties.Count > 0)\n{\n    request.Annotations.Add(annotation);\n    await client.Inbox.StoreAsync(request);\n}","handlingStrategy":"validation","validationCode":"if (annotations == null || annotations.Count == 0 || annotations.Any(a => a.Properties.Count == 0))\n    throw new ArgumentException(\"all annotations must define at least one property\", nameof(annotations));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call SetProperty on each ImapAnnotation before adding it to a store request","Filter out empty annotations before StoreAsync","Centralize annotation construction in one helper that rejects empty property sets"],"tags":["imap","argument-validation","annotations","mailkit"],"backgroundTag":"empty-required-field","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}