dotnet/BenchmarkDotNet · error · ArgumentNullException
Value cannot be null. (Parameter 'values')
Error message
Value cannot be null. (Parameter 'values')
What it means
CreateArgumentTextRepresentation throws ArgumentNullException(nameof(values)) when the values array is null. Because values is a params parameter, a null array is only produced by explicitly passing null (e.g. new MsBuildProperty("name", null) where the compiler binds null to string[]); omitting values yields an empty array, not null.
Source
Thrown at src/BenchmarkDotNet/Jobs/Argument.cs:126
/// An MSBuild property argument (<c>/p:name=value</c>).
/// It escapes MSBuild special characters in the value (for example, semicolons) so that
/// list-like values can be passed without manual encoding.
/// </summary>
[PublicAPI]
public class MsBuildProperty : MsBuildArgument
{
public MsBuildProperty(string name, params string[] values)
: base(CreateArgumentTextRepresentation(name, values), escapeSpecialCharacters: true)
{
}
private static string CreateArgumentTextRepresentation(string name, string[] values)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Property name must be non-empty.", nameof(name));
if (values is null)
throw new ArgumentNullException(nameof(values));
for (int i = 0; i < values.Length; i++)
if (values[i] is null)
throw new ArgumentException("Property values can not contain null.", nameof(values));
string value = values.Length switch
{
0 => string.Empty,
1 => values[0],
_ => string.Join(";", values)
};
return $"/p:{name}={value}";
}
}
}
View on GitHub (pinned to b515068b61)
Solutions
- Omit values entirely for an empty property: new MsBuildProperty("name").
- Coalesce a null array to an empty one before passing: values ?? Array.Empty<string>().
- Pass a concrete value: new MsBuildProperty("name", "value").
Example fix
// before
job.WithArgument(new MsBuildProperty("MyCustomSetting", null));
// after
job.WithArgument(new MsBuildProperty("MyCustomSetting")); Defensive patterns
Strategy: validation
Validate before calling
var safeValues = values ?? Array.Empty<string>(); job.WithArgument(new MsBuildProperty(name, safeValues));
Prevention
- Omit the values argument for an empty property instead of passing null.
- Coalesce possibly-null arrays before forwarding them.
- Remember params binds a single null literal to the array, not to an element.
When it happens
Trigger: Calling new MsBuildProperty("name", null) (null binds to the params array), or passing a string[] variable that is null as the values argument.
Common situations: Passing a single null literal expecting an empty value, forwarding a possibly-null array variable, or constructing properties in a loop over a null collection.
Related errors
- Property name must be non-empty.
- The value {value} is not assignable to {characteristic} prop
- String cannot be empty.
- String cannot be empty or whitespace.
- {name} can't be null
AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13).
Data as JSON: /api/errors/09e3130f779bc588.
Report an issue: GitHub.