stride3d/stride · error · ArgumentException

can't be null, empty, or consist only of whitespace…

Error message

{paramName} can't be null, empty, or consist only of whitespace characters.

What it means

ArgumentCheck.NotWhiteSpace throws ArgumentException when a string is null, empty, or consists only of whitespace characters. Null is caught first by NotNull (as ArgumentNullException); empty/whitespace strings raise this ArgumentException with a message naming the parameter.

Solutions

  1. Provide a non-blank string value (trim and validate input before the call)
  2. Fix the config/env source: replace blank values with real ones and fail fast at load time with a clear message
  3. Use string.IsNullOrWhiteSpace in the caller to pre-validate and produce a better error
  4. If only null/empty should be rejected but pure whitespace is acceptable, use NotEmpty (string) instead

Example fix

// before
var path = Environment.GetEnvironmentVariable("OUTPUT_DIR"); // "  "
ArgumentCheck.NotWhiteSpace(path, nameof(path));
// after
var path = Environment.GetEnvironmentVariable("OUTPUT_DIR")?.Trim();
if (string.IsNullOrWhiteSpace(path))
    throw new InvalidDataException("OUTPUT_DIR environment variable must be set to a non-blank path");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(text))
    throw new ArgumentException("A non-blank string is required", nameof(text));

Type guard

bool IsNotBlank([NotNullWhen(true)] string? s) => !string.IsNullOrWhiteSpace(s);

Try / catch

try { NotWhiteSpace(configValue, nameof(configValue)); }
catch (ArgumentException ex) when (ex.ParamName == nameof(configValue))
{
    // report missing/blank configuration with field name
}

Prevention

When it happens

Trigger: Calling ArgumentCheck.NotWhiteSpace(variable, variableName) with "", " ", "\t\n", or any string where string.IsNullOrWhiteSpace returns true; a config key present but set to blank spaces.

Common situations: User left a required text field blank or entered spaces; YAML/JSON config has `key: ""` or `key: " "`; environment variables set to empty string; trimming removed all meaningful content.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/296c964f0c709a82. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/ArgumentCheck.cs:205

        /// <remarks>
        /// Before checking the <paramref name="variable"/>, a call is made to
        /// <see cref="NotNull"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="variable"/> cannot be <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="variable"/> cannot be an empty <see cref="string"/> or consists only of white-space characters.
        /// </exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void NotWhiteSpace(string variable, string variableName)
        {
            var paramName = variableName ?? "The variable";
            // Variable cannot be null
            NotNull(variable, paramName);
            if (string.IsNullOrWhiteSpace(variable))
            {
                throw new ArgumentException($"{paramName} can't be null, empty, or consist only of whitespace characters.");
            }
        }
    }

    /// <summary>
    /// Same as <see cref="ArgumentCheck"/> but only in DEBUG release.
    /// </summary>
    public static class ArgumentDebugCheck
    {
        /// <summary>
        /// Checks wether the <paramref name="variable"/> meets the <see cref="predicate"/>.
        /// Otherwise throws an exception.
        /// </summary>
        /// <typeparam name="T">The type of the <paramref name="variable"/>.</typeparam>
        /// <param name="variable">The value to check.</param>
        /// <param name="predicate">The predicate that implements the condition.</param>
        /// <param name="variableName">The name of the variable being checked.</param>
        /// <exception cref="ArgumentException">

View on GitHub (pinned to 96fad776d2)