dotnet/BenchmarkDotNet · error · ArgumentException

String cannot be empty or whitespace.

Error message

String cannot be empty or whitespace.

What it means

Thrown by the ThrowIfNullOrWhiteSpace polyfill. After the null check, string.IsNullOrWhiteSpace(argument) returns true for whitespace-only input, raising ArgumentException ("String cannot be empty or whitespace."). Stricter than ThrowIfNullOrEmpty: it also rejects " ", tabs, and other whitespace.

Source

Thrown at src/BenchmarkDotNet/Extensions/Polyfills/ArgumentExceptionExtensions.cs:31

            [CallerArgumentExpression(nameof(argument))] string? paramName = null)
        {
            if (argument is null)
                throw new ArgumentNullException(paramName);

            if (argument.Length == 0)
                throw new ArgumentException("String cannot be empty.", paramName);
        }

        public static void ThrowIfNullOrWhiteSpace([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
        {
            if (argument is null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (string.IsNullOrWhiteSpace(argument))
            {
                throw new ArgumentException("String cannot be empty or whitespace.", paramName);
            }
        }
    }
}
#endif

View on GitHub (pinned to b515068b61)

Solutions

  1. Trim and verify the value is non-empty before assigning it (string.IsNullOrWhiteSpace check).
  2. Provide a real identifier/path/value instead of whitespace.
  3. If whitespace is legitimately possible, sanitize it upstream so the validated API only ever sees trimmed content.

Example fix

// before
var name = "   ";

// after
var name = "MyBenchmark";
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(value)) throw new InvalidOperationException("value must be non-empty/whitespace");

Prevention

When it happens

Trigger: An internal BenchmarkDotNet validation runs ThrowIfNullOrWhiteSpace on a string that is empty or consists only of whitespace characters (spaces, tabs, newlines).

Common situations: Whitespace leaked from trimmed user input, config files with blank-but-whitespace values, copy-paste of a path padded with spaces, or code that sets a label/name to " " by mistake.

Related errors


AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13). Data as JSON: /api/errors/78279eee7374e8b7. Report an issue: GitHub.