{"record":{"id":"9b5f2584a4ef3033","repo":"jstedfast/MailKit","slug":"the-language-code-cannot-be-empty","errorCode":null,"errorMessage":"The language code cannot be empty.","messagePattern":"The language code cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Pop3/Pop3Client.cs","lineNumber":1734,"sourceCode":"\t\tpublic IList<Pop3Language> GetLanguages (CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tvar pc = QueueLangCommand (out var langs);\n\n\t\t\tengine.Run (true, cancellationToken);\n\n\t\t\treturn new ReadOnlyCollection<Pop3Language> (langs);\n\t\t}\n\n\t\tvoid CheckCanSetLanguage (string lang)\n\t\t{\n\t\t\tCheckDisposed ();\n\t\t\tCheckConnected ();\n\n\t\t\tif (lang == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (lang));\n\n\t\t\tif (lang.Length == 0)\n\t\t\t\tthrow new ArgumentException (\"The language code cannot be empty.\", nameof (lang));\n\n\t\t\tif ((Capabilities & Pop3Capabilities.Lang) == 0)\n\t\t\t\tthrow new NotSupportedException (\"The POP3 server does not support the LANG extension.\");\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Set the language used by the POP3 server for error messages.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// If the POP3 server supports the LANG extension, it is possible to\n\t\t/// set the language used by the POP3 server for error messages.\n\t\t/// </remarks>\n\t\t/// <param name=\"lang\">The language code.</param>\n\t\t/// <param name=\"cancellationToken\">The cancellation token.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"lang\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentException\">","sourceCodeStart":1716,"sourceCodeEnd":1752,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Pop3/Pop3Client.cs#L1716-L1752","documentation":"Pop3Client.SetLanguage validates the lang argument and throws this ArgumentException when the language code string is non-null but empty. An empty string can never be a valid RFC 8158 language tag, so MailKit rejects it immediately before any network traffic.","triggerScenarios":"Calling SetLanguage(\"\") or SetLanguage(string.Empty); passing a language variable that was initialized to \"\" and never populated (e.g. failed lookup or split of an empty setting string).","commonSituations":"Reading a language code from configuration that defaults to empty; parsing a header or user preference that yielded \"\"; code path where lang = selectedLanguage && selectedLanguage is empty.","solutions":["Pass a valid language tag such as \"en\" or \"de\" obtained from client.GetLanguages().","Guard the call: if (!string.IsNullOrEmpty (lang)) client.SetLanguage (lang, ...).","Fix the configuration/default so the language setting is never an empty string.","Catch ArgumentException and fall back to the server default language."],"exampleFix":"// before\nclient.SetLanguage (config.Language, cancellationToken); // config.Language == \"\"\n// after\nif (!string.IsNullOrEmpty (config.Language))\n    client.SetLanguage (config.Language, cancellationToken);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty (lang))\n    throw new ArgumentException (\"Language code must be a non-empty RFC 8158 tag\", nameof (lang));","typeGuard":null,"tryCatchPattern":"try {\n    client.SetLanguage (lang, cancellationToken);\n} catch (ArgumentException) {\n    // empty/invalid language code: use server default\n}","preventionTips":["Validate configured language values at startup, not at call time","Only pass codes obtained from client.GetLanguages()","Treat empty settings as 'use default' instead of forwarding them"],"tags":["pop3","argument","empty-string","mailkit","validation"],"backgroundTag":"empty-required-field","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"}