{"record":{"id":"d815975e482e9ffd","repo":"jstedfast/MailKit","slug":"bodyparts","errorCode":null,"errorMessage":"bodyParts","messagePattern":"bodyParts","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/BodyPartMultipart.cs","lineNumber":89,"sourceCode":"\t\t/// Initializes a new instance of the <see cref=\"MailKit.BodyPartMultipart\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Creates a new <see cref=\"BodyPartMultipart\"/>.\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/// <param name=\"bodyParts\">The child body parts of the multipart.</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/// <para>-or-</para>\n\t\t/// <para><paramref name=\"bodyParts\"/> is <see langword=\"null\" />.</para>\n\t\t/// </exception>\n\t\tpublic BodyPartMultipart (ContentType contentType, string partSpecifier, BodyPartCollection bodyParts) : base (contentType, partSpecifier)\n\t\t{\n\t\t\tif (bodyParts is null)\n\t\t\t\tthrow new ArgumentNullException (nameof (bodyParts));\n\n\t\t\tBodyParts = bodyParts;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Gets the child body parts.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the child body parts.\n\t\t/// </remarks>\n\t\t/// <value>The child body parts.</value>\n\t\tpublic BodyPartCollection BodyParts {\n\t\t\tget; private set;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Gets the Content-Disposition of the body part, if available.\n\t\t/// </summary>","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/BodyPartMultipart.cs#L71-L107","documentation":"The BodyPartMultipart constructor throws ArgumentNullException when the bodyParts parameter is null. A multipart body part is defined by its child parts, so an empty collection is valid but null is not; the constructor validates and assigns it to the BodyParts property. This is fail-fast validation of a required constructor argument.","triggerScenarios":"Calling new BodyPartMultipart(contentType, partSpecifier, null), e.g. when a child-part list came from a deserializer or parser that returned null for a multipart/* body structure.","commonSituations":"Rebuilding parsed IMAP BODYSTRUCTURE trees in tests or custom parsers where the children collection is null because no child parts were parsed; or caching a collection variable that was never initialized.","solutions":["Pass a non-null BodyPartCollection; use an empty BodyPartCollection if the multipart part has no children yet.","Coalesce: pass bodyParts ?? new BodyPartCollection() when null means 'no children'.","Fix the upstream parser/deserializer so it returns an empty collection rather than null."],"exampleFix":"// before\nvar multipart = new BodyPartMultipart(contentType, \"1\", childParts); // childParts may be null\n// after\nvar multipart = new BodyPartMultipart(contentType, \"1\", childParts ?? new BodyPartCollection());","handlingStrategy":"validation","validationCode":"if (childParts is null)\n    childParts = new BodyPartCollection();\nvar multipart = new BodyPartMultipart(contentType, partSpecifier, childParts);","typeGuard":"bool IsValidMultipartInput(BodyPartCollection? parts) => parts is not null;","tryCatchPattern":"try {\n    var multipart = new BodyPartMultipart(contentType, specifier, parts);\n} catch (ArgumentNullException ex) when (ex.ParamName == \"bodyParts\") {\n    parts = new BodyPartCollection();\n}","preventionTips":["Treat 'no children' as an empty BodyPartCollection, never null.","Ensure custom BODYSTRUCTURE parsers always return a collection (possibly empty) for multipart/* parts.","Enable nullable reference types so null-collection flow is caught at compile time."],"tags":["null-reference","constructor","argument-validation","mailkit"],"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"}