dotnet/BenchmarkDotNet · error · NotSupportedException

Benchmark {benchmark.Name} has invalid type of arguments pro

Error message

Benchmark {benchmark.Name} has invalid type of arguments provided by [ArgumentsSource({valuesInfo.source.Name})]. It should be IEnumerable<object[]> or IEnumerable<object>.

What it means

Thrown by SmartParamBuilder.CreateForArguments as a fallback NotSupportedException when the value yielded by [ArgumentsSource] is neither an object[] (for multi-parameter benchmarks) nor a single object (for single-parameter benchmarks) that the builder can process. This is the terminal else-branch after all recognized shapes (array for multi-param, single object for one-param) have been checked.

Source

Thrown at src/BenchmarkDotNet/Parameters/SmartParamBuilder.cs:57

                        [Create(parameterDefinitions, array[0], valuesInfo.source, sourceIndex, argumentIndex: 0, summaryStyle)]);
                }

                if (parameterDefinitions.Length > 1)
                {
                    if (parameterDefinitions.Length != array.Length)
                        throw new InvalidOperationException($"Benchmark {benchmark.Name} has invalid number of arguments provided by [ArgumentsSource({valuesInfo.source.Name})]! {array.Length} instead of {parameterDefinitions.Length}.");

                    return new ParameterInstances(
                        array.Select((value, argumentIndex) => Create(parameterDefinitions, value, valuesInfo.source, sourceIndex, argumentIndex, summaryStyle)).ToArray());
                }
            }

            if (parameterDefinitions.Length == 1)
            {
                return new ParameterInstances([Create(parameterDefinitions, unwrappedValue, valuesInfo.source, sourceIndex, argumentIndex: 0, summaryStyle)]);
            }

            throw new NotSupportedException($"Benchmark {benchmark.Name} has invalid type of arguments provided by [ArgumentsSource({valuesInfo.source.Name})]. It should be IEnumerable<object[]> or IEnumerable<object>.");
        }

        private static ParameterInstance Create(ParameterDefinition[] parameterDefinitions, object value, MemberInfo source, int sourceIndex, int argumentIndex, SummaryStyle summaryStyle)
        {
            if (SourceCodeHelper.IsCompilationTimeConstant(value))
                return new ParameterInstance(parameterDefinitions[argumentIndex], value, summaryStyle);

            return new ParameterInstance(parameterDefinitions[argumentIndex], new SmartArgument(parameterDefinitions, value, source, sourceIndex, argumentIndex), summaryStyle);
        }
    }

    internal class SmartArgument : IParam
    {
        private readonly ParameterDefinition[] parameterDefinitions;
        private readonly MemberInfo source;
        private readonly int sourceIndex;
        private readonly int argumentIndex;

View on GitHub (pinned to b515068b61)

Solutions

  1. For multi-parameter benchmarks, change the source to return IEnumerable<object[]> where each object[] has one element per parameter.
  2. For single-parameter benchmarks, ensure the source returns IEnumerable<object> or IEnumerable<T>.
  3. Verify the return type of the source member matches the benchmark parameter count.

Example fix

// before (multi-param benchmark)
public IEnumerable<int> Data() => new[] { 1, 2, 3 };
[Benchmark]
[ArgumentsSource(nameof(Data))]
public void Run(int a, int b) { }

// after
public IEnumerable<object[]> Data() => new[]
{
    new object[] { 1, 2 },
    new object[] { 3, 4 },
};
Defensive patterns

Strategy: validation

Validate before calling

// For multi-parameter benchmarks, ensure source returns IEnumerable<object[]>
var sourceType = typeof(MyBench).GetMethod(nameof(MyBench.Data))!.ReturnType;
if (paramCount > 1 && !typeof(IEnumerable<object[]>).IsAssignableFrom(sourceType))
    throw new InvalidOperationException("Multi-param benchmarks need IEnumerable<object[]> source.");

Prevention

When it happens

Trigger: A benchmark method has more than one parameter but [ArgumentsSource] yields individual scalar values (not wrapped in object[]), or yields a type that is neither IEnumerable<object[]> nor IEnumerable<object>. For example, yielding ints from a source for a two-parameter method.

Common situations: Misunderstanding the ArgumentsSource contract: for multi-parameter benchmarks the source must yield object[] (one array per test case), not individual values. Also from returning non-enumerable types or nested structures.

Related errors


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