{"record":{"id":"9f493099e6cd345e","repo":"jstedfast/MailKit","slug":"contenttype","errorCode":null,"errorMessage":"contentType","messagePattern":"contentType","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/BodyPart.cs","lineNumber":79,"sourceCode":"\t\t}\n\n\t\t/// <summary>\n\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}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/BodyPart.cs#L61-L97","documentation":"The protected BodyPart(ContentType, string) constructor throws ArgumentNullException when the contentType parameter is null. MailKit requires every BODYSTRUCTURE part to carry a parsed MIME ContentType, so a null value would leave the part in an invalid state. The parameter name is reported via nameof, which is why the message is exactly \"contentType\".","triggerScenarios":"Calling the protected constructor from a derived BodyPart subclass and passing a null ContentType — e.g. new MyBodyPart(null, \"1\").","commonSituations":"Custom subclassing of BodyPart when the MIME Content-Type header was missing or failed to parse and the caller passes null instead of a default like text/plain; refactoring code that previously accepted a nullable content type.","solutions":["Pass a valid parsed ContentType, e.g. new ContentType(\"text\", \"plain\"), instead of null","If the source MIME part had no Content-Type header, default to new ContentType(\"text\",\"plain\") per RFC 2045","Guard the value before invoking the constructor and throw a more descriptive error"],"exampleFix":"// before\nvar part = new CustomBodyPart(contentType, \"1\"); // contentType was null\n// after\ncontentType ??= new ContentType(\"text\", \"plain\");\nvar part = new CustomBodyPart(contentType, \"1\");","handlingStrategy":"validation","validationCode":"if (contentType == null) throw new ArgumentException(\"A parsed ContentType is required; use new ContentType(\\\"text\\\", \\\"plain\\\") when the MIME header is missing.\", nameof(contentType));","typeGuard":"static bool HasContentType(ContentType? ct) => ct is not null;","tryCatchPattern":"try { var part = new CustomBodyPart(contentType, specifier); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"contentType\") { /* supply default ContentType and retry */ }","preventionTips":["Default missing MIME Content-Type headers to text/plain per RFC 2045 before constructing parts","Use nameof-based null checks in subclass constructors matching the base class contract","Never pass nullable values straight into BodyPart constructors"],"tags":["mailkit","null-argument","mime","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"}