{"record":{"id":"d7fda2b1a2b3b720","repo":"jstedfast/MailKit","slug":"partspecifier","errorCode":null,"errorMessage":"partSpecifier","messagePattern":"partSpecifier","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/BodyPart.cs","lineNumber":82,"sourceCode":"\t\t/// Initializes a new instance of the <see cref=\"MailKit.BodyPart\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"MailKit.BodyPart\"/>.\n\t\t/// </remarks>\n\t\t/// <param name=\"contentType\">The content type.</param>\n\t\t/// <param name=\"partSpecifier\">The part specifier.</param>\n\t\t/// <exception cref=\"ArgumentNullException\">\n\t\t/// <para><paramref name=\"contentType\"/> is <see langword=\"null\" />.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"partSpecifier\"/> is <see langword=\"null\" />.</para>\n\t\t/// </exception>\n\t\tprotected BodyPart (ContentType contentType, string partSpecifier)\n\t\t{\n\t\t\tif (contentType == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (contentType));\n\n\t\t\tif (partSpecifier == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (partSpecifier));\n\n\t\t\tContentType = contentType;\n\t\t\tPartSpecifier = partSpecifier;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Gets the Content-Type of the body part.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the Content-Type of the body part.\n\t\t/// </remarks>\n\t\t/// <value>The content type.</value>\n\t\tpublic ContentType ContentType {\n\t\t\tget; set;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Gets the part specifier.","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/BodyPart.cs#L64-L100","documentation":"The protected BodyPart(ContentType, string) constructor throws ArgumentNullException when the partSpecifier parameter is null. The part specifier (IMAP BODY section string such as \"1.2\" or \"TEXT\") is a required identity for every body part. The message is the parameter name \"partSpecifier\" thrown via ArgumentNullException.","triggerScenarios":"Calling the protected constructor from a derived BodyPart subclass with a null specifier — e.g. new MyBodyPart(new ContentType(\"text\",\"plain\"), null).","commonSituations":"Custom BodyPart subclasses built outside the parser when the IMAP BODYSTRUCTURE section identifier was not captured; constructing parts programmatically where the specifier was assumed optional.","solutions":["Pass the correct IMAP section specifier string, using string.Empty for the top-level message part as TryParse does","Fall back to string.Empty instead of null when no specifier is known","Guard against null before constructing"],"exampleFix":"// before\nvar part = new CustomBodyPart(contentType, partSpecifier); // partSpecifier was null\n// after\npartSpecifier ??= string.Empty;\nvar part = new CustomBodyPart(contentType, partSpecifier);","handlingStrategy":"validation","validationCode":"if (partSpecifier == null) partSpecifier = string.Empty; // top-level parts use an empty specifier","typeGuard":"static bool HasSpecifier(string? s) => s is not null;","tryCatchPattern":"try { var part = new CustomBodyPart(contentType, specifier); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"partSpecifier\") { specifier = string.Empty; part = new CustomBodyPart(contentType, specifier); }","preventionTips":["Use string.Empty, not null, when a part has no IMAP section specifier","Keep the specifier captured wherever the BODYSTRUCTURE response is stored","Enable nullable reference types so null specifier strings are flagged at compile time"],"tags":["mailkit","null-argument","imap","bodystructure"],"backgroundTag":"null-argument","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"}