{"record":{"id":"8a3437b32d2985e5","repo":"jstedfast/MailKit","slug":"value-cannot-be-null-parameter-partspecifier","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'partSpecifier')","messagePattern":"Value cannot be null\\. \\(Parameter 'partSpecifier'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationEntry.cs","lineNumber":158,"sourceCode":"\t\t\t\tif ((pc == '/' || pc == '.') && (c == '/' || c == '.'))\n\t\t\t\t\tthrow new ArgumentException (\"Invalid annotation entry path.\", nameof (path));\n\n\t\t\t\tpc = c;\n\t\t\t}\n\n\t\t\tint endIndex = path.Length - 1;\n\n\t\t\tif (path[endIndex] == '/')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not end with '/'.\", nameof (path));\n\n\t\t\tif (path[endIndex] == '.')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not end with '.'.\", nameof (path));\n\t\t}\n\n\t\tstatic void ValidatePartSpecifier (string partSpecifier)\n\t\t{\n\t\t\tif (partSpecifier == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (partSpecifier));\n\n\t\t\tchar pc = '\\0';\n\n\t\t\tfor (int i = 0; i < partSpecifier.Length; i++) {\n\t\t\t\tchar c = partSpecifier[i];\n\n\t\t\t\tif (!((c >= '0' && c <= '9') || c == '.') || (c == '.' && (pc == '.' || pc == '\\0')))\n\t\t\t\t\tthrow new ArgumentException (\"Invalid part-specifier.\", nameof (partSpecifier));\n\n\t\t\t\tpc = c;\n\t\t\t}\n\n\t\t\tif (pc == '.')\n\t\t\t\tthrow new ArgumentException (\"Invalid part-specifier.\", nameof (partSpecifier));\n\t\t}\n\n\t\tAnnotationEntry (string? partSpecifier, string entry, string path, AnnotationScope scope)\n\t\t{","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationEntry.cs#L140-L176","documentation":"AnnotationEntry.ValidatePartSpecifier throws ArgumentNullException when the partSpecifier argument is null. The part specifier identifies the MIME part (e.g. \"1.2\" or \"text\") the annotation applies to; a null value cannot form a valid entry.","triggerScenarios":"Passing a null partSpecifier to an AnnotationEntry constructor/factory overload that takes one, typically because a BodyPart.PartSpecifier lookup returned null or a variable was never initialized.","commonSituations":"Deriving the part specifier from parsed message metadata that lacked a value; calling the partSpecifier-based constructor instead of the BodyPart-based one when no part exists.","solutions":["Pass a valid non-null part specifier string (e.g. \"1\" or \"text\")","If the annotation is for the whole message, use the constructor overload without a part specifier instead of passing null","Null-check or coalesce the value before calling: partSpecifier ?? \"\""],"exampleFix":"// before\nvar entry = AnnotationEntry.Create (null, \"comment\", AnnotationScope.Both);\n// after\nvar entry = AnnotationEntry.Create (\"1\", \"comment\", AnnotationScope.Both);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty (partSpecifier))\n    throw new ArgumentException (\"Part specifier is required (e.g. \\\"1\\\" or \\\"1.2\\\").\");","typeGuard":"bool IsValidPartSpecifier (string? s) =>\n    !string.IsNullOrEmpty (s) && s.All (c => char.IsDigit (c) || c == '.')\n    && !s.StartsWith (\".\") && !s.EndsWith (\".\") && !s.Contains (\"..\");","tryCatchPattern":"try {\n    var entry = AnnotationEntry.Create (partSpecifier, path, scope);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"partSpecifier\") {\n    logger.LogError (ex, \"Part specifier was null\");\n}","preventionTips":["Null-check values derived from BodyPart.PartSpecifier before use","Use the constructor overload matching the data you actually have","Prefer compiling the part specifier from known integers rather than parsing strings"],"tags":["imap","annotation","null-argument"],"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"}