Unity-Technologies/UnityCsReference · error · ArgumentNullException

Dialog message text cannot be null or whitespace.

Error message

Dialog message text cannot be null or whitespace.

What it means

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.

Source

Thrown at Editor/Mono/EditorDialog.cs:208

            // XML tags (Linux), Windows Registry key names, or NSPreference dictionaries
            // (which are all valid XML tags), but this will simplify the validation for API users.
            // Our EditorPrefs are stored in the registry, with this key as the path.
            // The maximum length of a registry key is 255 characters, so we limit the key
            // to account for the "Software\Unity Technologies\Unity Editor 5.x Automated Testing\" prefix and a 12 character suffix.
            // We also prefix the key with "DialogOptOut." (13 chars) to ensure that it is unique to the dialog box API.
            // For this reason, we will limit to a safer ~ 127 character limit.

            // This regular expression ensures that the key string:
            // Contains only alphanumeric characters, periods, underscores, and hyphens.
            // Is between 1 and 127 characters long.
            if (string.IsNullOrEmpty(optOutKey) || !Regex.IsMatch(optOutKey, @"^[A-Za-z0-9._-]{1,127}$"))
                throw new ArgumentException($"Key must be non-null, between 1 and 127 characters, and be a valid XML tag.", nameof(optOutKey));
        }

        private static void ThrowIfMessageIsInvalid(string messageText)
        {
            if (string.IsNullOrWhiteSpace(messageText))
                throw new ArgumentNullException(nameof(messageText), "Dialog message text cannot be null or whitespace.");
        }

        private static void ThrowIfButtonTextIsInvalid(string buttonText, string parameterName)
        {
            const int kMaxButtonTextLength = 64; // This limit is probably not necessary, but it's good to have a limit on the button text as well.
            if (buttonText != null && buttonText.Length > kMaxButtonTextLength)
                throw new ArgumentException($"Text on buttons must be less than {kMaxButtonTextLength} characters long.", parameterName);
        }

        /// <summary>
        /// Displays a simple alert dialog box with a title, an icon, a message, and a single button.
        /// </summary>
        /// <param name="messageText">The message to display in the dialog box.</param>
        /// <param name="iconType">The icon to display in the dialog box. Defaults to <see cref="DialogIconType.Warning"/>.</param>
        /// <param name="titleText">The title of the dialog box. If left null, defaults to "Unity".</param>
        /// <param name="buttonText">The text to display on the button. If left null, defaults to "OK".</param>
        /// <remarks>
        /// If <paramref name="messageText"/> is null or whitespace, an <see cref="ArgumentNullException"/> is thrown.

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Provide a guaranteed non-blank fallback message before calling.
  2. Validate: if (string.IsNullOrWhiteSpace(msg)) msg = "(no message)";
  3. Audit localized message tables for empty entries.

Example fix

// before
EditorDialog.DisplayDialog("Title", maybeNullMessage, "OK");
// after
string msg = string.IsNullOrWhiteSpace(maybeNullMessage) ? "Operation completed." : maybeNullMessage;
EditorDialog.DisplayDialog("Title", msg, "OK");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(messageText))
    messageText = "(no message)";

Type guard

static bool IsValidMessage(string m) => !string.IsNullOrWhiteSpace(m);

Prevention

When it happens

Trigger: Calling an EditorDialog.DisplayDialog overload with messageText that is null, string.Empty, or all whitespace (spaces/tabs/newlines).

Common situations: 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.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/47bb628a6cc815ed. Report an issue: GitHub.