dotnet/BenchmarkDotNet · error · NotSupportedException

Default BenchmarkActionFactory does not support custom async

Error message

Default BenchmarkActionFactory does not support custom async enumerables besides IAsyncEnumerable<T> and ConfiguredCancelAsyncEnumerable<T>

What it means

The default InProcess NoEmit BenchmarkActionFactory supports consuming IAsyncEnumerable<T> and ConfiguredCancelAsyncEnumerable<T> only; other custom async enumerable types are rejected.

Source

Thrown at src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/BenchmarkActionFactory.cs:100

        {
            var asyncEnumerableInterface = typeof(IAsyncEnumerable<>).MakeGenericType(asyncEnumerableInfo.ItemType);
            if (asyncEnumerableInterface.IsAssignableFrom(resultType))
            {
                return Create(
                    typeof(BenchmarkActionAsyncEnumerable<>).MakeGenericType(asyncEnumerableInfo.ItemType),
                    resultInstance,
                    targetMethod,
                    unrollFactor);
            }
            if (resultType.IsGenericType && resultType.GetGenericTypeDefinition() == typeof(ConfiguredCancelableAsyncEnumerable<>))
            {
                return Create(
                    typeof(BenchmarkActionConfiguredCancelableAsyncEnumerable<>).MakeGenericType(asyncEnumerableInfo.ItemType),
                    resultInstance,
                    targetMethod,
                    unrollFactor);
            }
            throw new NotSupportedException(
                $"Default {nameof(BenchmarkActionFactory)} does not support custom async enumerables besides IAsyncEnumerable<T> and ConfiguredCancelableAsyncEnumerable<T>");
        }

        return Create(
            typeof(BenchmarkAction<>).MakeGenericType(resultType),
            resultInstance,
            targetMethod,
            unrollFactor);
    }

    private static void PrepareInstanceAndResultType(object instance, MethodInfo targetMethod, out object? resultInstance, out Type resultType)
    {
        resultInstance = targetMethod.IsStatic ? null : instance;
        resultType = targetMethod.ReturnType;

        if (resultType == typeof(void))
        {
            // DONTTOUCH: async should be checked for target method

View on GitHub (pinned to b515068b61)

Solutions

  1. Return IAsyncEnumerable<T> (or ConfiguredCancelAsyncEnumerable<T>) from the benchmark instead of a custom async enumerable.
  2. Implement a custom BenchmarkActionFactory that knows how to consume your async enumerable type.
  3. Use the default out-of-process toolchain if you cannot change the return type.

When it happens

Trigger: Thrown at src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/BenchmarkActionFactory.cs:100 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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