dotnet/BenchmarkDotNet · error · InvalidBenchmarkDeclarationException
{memberInfo.Name} of type {type.Name} does not implement IEn
Error message
{memberInfo.Name} of type {type.Name} does not implement IEnumerable, unable to read values for [ParamsSource] What it means
Thrown by ToArray when the member referenced by [ParamsSource] returns a value that does not implement IEnumerable. BenchmarkDotNet requires the source to produce a collection of values to enumerate for parameter generation; a non-enumerable return type (e.g., a single int, a custom object) cannot be iterated.
Source
Thrown at src/BenchmarkDotNet/Running/BenchmarkConverter.cs:328
paramsSourceMethod.Invoke(paramsSourceMethod.IsStatic ? null : Activator.CreateInstance(sourceType), null)!,
paramsSourceMethod,
sourceType));
var paramsSourceProperty = sourceType.GetAllProperties().FirstOrDefault(property => property.Name == sourceName && property.GetMethod?.IsPublic == true);
if (paramsSourceProperty == null)
throw new InvalidBenchmarkDeclarationException($"{sourceType.Name} has no public, accessible method/property called {sourceName}, unable to read values for [ParamsSource]");
return (paramsSourceProperty, ToArray(
paramsSourceProperty.GetValue(paramsSourceProperty.GetMethod!.IsStatic ? null : Activator.CreateInstance(sourceType)!)!,
paramsSourceProperty,
sourceType));
}
private static object[] ToArray(object sourceValue, MemberInfo memberInfo, Type type)
{
if (!(sourceValue is IEnumerable collection))
throw new InvalidBenchmarkDeclarationException($"{memberInfo.Name} of type {type.Name} does not implement IEnumerable, unable to read values for [ParamsSource]");
return collection.Cast<object>().ToArray();
}
private static object?[] GetAllValidValues(Type parameterType)
{
if (parameterType == typeof(bool))
return [false, true];
if (parameterType.GetTypeInfo().IsEnum)
{
if (parameterType.GetTypeInfo().IsDefined(typeof(FlagsAttribute)))
return [Activator.CreateInstance(parameterType)!];
return Enum.GetValues(parameterType).Cast<object>().ToArray();
}
var nullableUnderlyingType = Nullable.GetUnderlyingType(parameterType);View on GitHub (pinned to b515068b61)
Solutions
- Change the source member to return IEnumerable<T> or IEnumerable<object>, e.g. a list or array.
- Wrap a single value in a collection if only one value is needed: new[] { 42 }.
- Ensure the return type implements IEnumerable (arrays, List<T>, HashSet<T>, etc.).
Example fix
// before
public int Source => 42;
[Params]
[ParamsSource(nameof(Source))]
public int Number;
// after
public IEnumerable<int> Source => new[] { 42 };
[Params]
[ParamsSource(nameof(Source))]
public int Number; Defensive patterns
Strategy: validation
Validate before calling
var member = typeof(MyBench).GetProperty(nameof(MyBench.Source))?.PropertyType
?? typeof(MyBench).GetMethod(nameof(MyBench.Source))?.ReturnType;
if (member is null || !typeof(IEnumerable).IsAssignableFrom(member))
throw new InvalidOperationException("ParamsSource member must return an IEnumerable."); Type guard
static bool IsEnumerableSource(Type? sourceReturnType) =>
sourceReturnType is not null && typeof(IEnumerable).IsAssignableFrom(sourceReturnType); Prevention
- Type the ParamsSource member's return type as IEnumerable<T> or T[] for compile-time safety.
- Never return a single scalar value from a ParamsSource; always wrap in a collection.
- Add a unit test that materializes the source to catch type issues early.
When it happens
Trigger: Declaring [ParamsSource(nameof(Source))] where Source is a public property/method returning a non-IEnumerable type, e.g. public int Source => 42 or public MyCustomObject Source => new MyCustomObject().
Common situations: Misunderstanding that ParamsSource must return a collection. Accidentally returning a single value. Declaring a property that returns a custom type without implementing IEnumerable.
Related errors
- {sourceType.Name} has no public, accessible method/property
- Benchmark {benchmark.Name} has invalid type of arguments pro
- {type.Name} is generic type definition, use BenchmarkSwitche
- {methodType} method {methodInfo.Name} has incorrect signatur
- {methodType} method {methodInfo.Name} has incorrect access m
AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13).
Data as JSON: /api/errors/edb57cb82cb718e0.
Report an issue: GitHub.