{"record":{"id":"47bb628a6cc815ed","repo":"Unity-Technologies/UnityCsReference","slug":"dialog-message-text-cannot-be-null-or-whitespace","errorCode":null,"errorMessage":"Dialog message text cannot be null or whitespace.","messagePattern":"Dialog message text cannot be null or whitespace\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorDialog.cs","lineNumber":208,"sourceCode":"            // XML tags (Linux), Windows Registry key names, or NSPreference dictionaries\n            // (which are all valid XML tags), but this will simplify the validation for API users.\n            // Our EditorPrefs are stored in the registry, with this key as the path.\n            // The maximum length of a registry key is 255 characters, so we limit the key\n            // to account for the \"Software\\Unity Technologies\\Unity Editor 5.x Automated Testing\\\" prefix and a 12 character suffix.\n            // We also prefix the key with \"DialogOptOut.\" (13 chars) to ensure that it is unique to the dialog box API.\n            // For this reason, we will limit to a safer ~ 127 character limit.\n\n            // This regular expression ensures that the key string:\n            // Contains only alphanumeric characters, periods, underscores, and hyphens.\n            // Is between 1 and 127 characters long.\n            if (string.IsNullOrEmpty(optOutKey) || !Regex.IsMatch(optOutKey, @\"^[A-Za-z0-9._-]{1,127}$\"))\n                throw new ArgumentException($\"Key must be non-null, between 1 and 127 characters, and be a valid XML tag.\", nameof(optOutKey));\n        }\n\n        private static void ThrowIfMessageIsInvalid(string messageText)\n        {\n            if (string.IsNullOrWhiteSpace(messageText))\n                throw new ArgumentNullException(nameof(messageText), \"Dialog message text cannot be null or whitespace.\");\n        }\n\n        private static void ThrowIfButtonTextIsInvalid(string buttonText, string parameterName)\n        {\n            const int kMaxButtonTextLength = 64; // This limit is probably not necessary, but it's good to have a limit on the button text as well.\n            if (buttonText != null && buttonText.Length > kMaxButtonTextLength)\n                throw new ArgumentException($\"Text on buttons must be less than {kMaxButtonTextLength} characters long.\", parameterName);\n        }\n\n        /// <summary>\n        /// Displays a simple alert dialog box with a title, an icon, a message, and a single button.\n        /// </summary>\n        /// <param name=\"messageText\">The message to display in the dialog box.</param>\n        /// <param name=\"iconType\">The icon to display in the dialog box. Defaults to <see cref=\"DialogIconType.Warning\"/>.</param>\n        /// <param name=\"titleText\">The title of the dialog box. If left null, defaults to \"Unity\".</param>\n        /// <param name=\"buttonText\">The text to display on the button. If left null, defaults to \"OK\".</param>\n        /// <remarks>\n        /// If <paramref name=\"messageText\"/> is null or whitespace, an <see cref=\"ArgumentNullException\"/> is thrown.","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorDialog.cs#L190-L226","documentation":"Thrown by EditorDialog.ThrowIfMessageIsInvalid when messageText is null, empty, or whitespace-only. The dialog requires non-blank message text because it is shown to the user and logged in markdown; a blank message would render an empty dialog. Note this is thrown as ArgumentNullException (with a message) — guard against both null and whitespace.","triggerScenarios":"Calling an EditorDialog.DisplayDialog overload with messageText that is null, string.Empty, or all whitespace (spaces/tabs/newlines).","commonSituations":"A localized message string that resolved to empty for the current locale; a message built from a null variable; programmatic dialogs passing a placeholder that was never filled.","solutions":["Provide a guaranteed non-blank fallback message before calling.","Validate: if (string.IsNullOrWhiteSpace(msg)) msg = \"(no message)\";","Audit localized message tables for empty entries."],"exampleFix":"// before\nEditorDialog.DisplayDialog(\"Title\", maybeNullMessage, \"OK\");\n// after\nstring msg = string.IsNullOrWhiteSpace(maybeNullMessage) ? \"Operation completed.\" : maybeNullMessage;\nEditorDialog.DisplayDialog(\"Title\", msg, \"OK\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(messageText))\n    messageText = \"(no message)\";","typeGuard":"static bool IsValidMessage(string m) => !string.IsNullOrWhiteSpace(m);","tryCatchPattern":null,"preventionTips":["Provide a non-blank fallback for every localized message string.","Audit localization tables for empty entries feeding dialogs.","Null-check variables before building dialog messages."],"tags":["editor","dialog","validation","null-argument","localization"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}