dotnet/BenchmarkDotNet · error · ArgumentException
String cannot be empty.
Error message
String cannot be empty.
What it means
Thrown by the ThrowIfNullOrEmpty polyfill in BenchmarkDotNet.Extensions.ArgumentExceptionExtensions. It mirrors ArgumentException.ThrowIfNullOrEmpty: a null argument raises ArgumentNullException first, then a zero-length string raises this ArgumentException ("String cannot be empty."). The library uses it to validate string-shaped configuration and identifier arguments internally.
Source
Thrown at src/BenchmarkDotNet/Extensions/Polyfills/ArgumentExceptionExtensions.cs:19
#if NET6_0 || NETSTANDARD2_0
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace System;
internal static partial class ArgumentExceptionExtensions
{
extension(ArgumentException)
{
public static void ThrowIfNullOrEmpty(
string? argument,
[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
- Supply a non-empty, meaningful string value to the configuration property that triggered it.
- If the value is optional, pass null (most validated APIs accept nullable) rather than an empty string.
- Trace the stack trace to the BenchmarkDotNet call site and pre-validate the originating config field with string.IsNullOrEmpty before assignment.
Example fix
// before config.ArtifactsPath = ""; // after config.ArtifactsPath = "./benchmark-results";
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(value)) throw new InvalidOperationException("value must be non-empty");
// or: guard the assignment to the BenchmarkDotNet config field Prevention
- Default optional config strings to null rather than empty.
- Add a string.IsNullOrEmpty check at the boundary where config is read into BenchmarkDotNet.
- Unit-test config construction with representative inputs.
When it happens
Trigger: Any internal BenchmarkDotNet call site invokes ArgumentException.ThrowIfNullOrEmpty(value) and the supplied string has Length == 0 (e.g. an empty artifacts path, empty job id, or empty column name passed into a validated API).
Common situations: Empty ArtifactsPath or output template, empty argument/property names, programmatic config that defaults an optional string to "" instead of null, or reading an unset environment/config value that resolves to an empty string.
Related errors
- String cannot be empty or whitespace.
- Property name must be non-empty.
- The value {value} is not assignable to {characteristic} prop
- Runtime Moniker not supported
- Please use job.Env.Jit to specify Jit in explicit way
AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13).
Data as JSON: /api/errors/08d15e587f338adb.
Report an issue: GitHub.