{"record":{"id":"0dc26443c6ba5146","repo":"jstedfast/MailKit","slug":"text","errorCode":null,"errorMessage":"text","messagePattern":"text","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/BodyPart.cs","lineNumber":729,"sourceCode":"\n\t\t/// <summary>\n\t\t/// Tries to parse the given text into a new <see cref=\"MailKit.BodyPart\"/> instance.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// <para>Parses a body part from the specified text.</para>\n\t\t/// <note type=\"note\">This syntax, while similar to IMAP's BODYSTRUCTURE syntax, is not completely\n\t\t/// compatible.</note>\n\t\t/// </remarks>\n\t\t/// <returns><see langword=\"true\" /> if the body part was successfully parsed; otherwise, <see langword=\"false\" />.</returns>\n\t\t/// <param name=\"text\">The text to parse.</param>\n\t\t/// <param name=\"part\">The parsed body part.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"text\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\tpublic static bool TryParse (string text, out BodyPart? part)\n\t\t{\n\t\t\tif (text == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (text));\n\n\t\t\tint index = 0;\n\n\t\t\treturn TryParse (text, ref index, string.Empty, out part) && index == text.Length;\n\t\t}\n\t}\n}\n","sourceCodeStart":711,"sourceCodeEnd":737,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/BodyPart.cs#L711-L737","documentation":"The static BodyPart.TryParse(string, out BodyPart?) throws ArgumentNullException when the text parameter is null. TryParse is designed to return false for malformed BODYSTRUCTURE strings, but a null input is treated as a programming error rather than a parse failure. The message is the parameter name \"text\".","triggerScenarios":"Calling BodyPart.TryParse(null, out var part), typically with a string obtained from an IMAP FETCH BODYSTRUCTURE response that was never assigned or was null in the ImapMessageSummary.","commonSituations":"Parsing a cached/remote BODYSTRUCTURE value that is null when the server omitted it (e.g. some responses for message/rfc822 or when fetching summary items without BODYSTRUCTURE); deserializing summaries from JSON where the field came back null.","solutions":["Check for null/empty before calling TryParse and skip parsing when absent","Re-fetch the summary with BodyStructure summary items requested (MessageSummaryItems.BodyStructure)","Coalesce null to string.Empty only if an empty parse result is acceptable"],"exampleFix":"// before\nBodyPart.TryParse(bodyStructureText, out var part); // text was null\n// after\nif (bodyStructureText != null && BodyPart.TryParse(bodyStructureText, out var part)) { ... }","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(bodyStructureText)) return; // skip parse when the server returned no BODYSTRUCTURE","typeGuard":"static bool CanParse(string? text) => !string.IsNullOrEmpty(text);","tryCatchPattern":"try { ok = BodyPart.TryParse(text, out var part); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"text\") { part = null; ok = false; }","preventionTips":["Request MessageSummaryItems.BodyStructure when fetching ImapMessageSummary items so the text is populated","Null-check strings obtained from caches, JSON, or network layers before parsing","Prefer TryParse's false return for malformed input; reserve null checks for truly absent data"],"tags":["mailkit","null-argument","imap","parsing"],"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"}