dotnet/BenchmarkDotNet · error · NotSupportedException
Async void is not supported by design.
Error message
Async void is not supported by design.
What it means
async void methods cannot be awaited or timed correctly, so BenchmarkDotNet rejects them by design; return Task instead.
Source
Thrown at src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/BenchmarkActionFactory.cs:122
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
// as fallbackIdleSignature used for result type detection only.
bool isUsingAsyncKeyword = targetMethod?.HasAttribute<AsyncStateMachineAttribute>() ?? false;
if (isUsingAsyncKeyword)
throw new NotSupportedException("Async void is not supported by design.");
}
else if (resultType.IsPointer && resultType != typeof(void*))
{
throw new NotSupportedException($"Default {nameof(BenchmarkActionFactory)} only supports void* return, not T*");
}
}
/// <summary>Helper to enforce .ctor signature.</summary>
private static BenchmarkActionBase Create(Type actionType, object? instance, MethodInfo method, int unrollFactor) =>
(BenchmarkActionBase)Activator.CreateInstance(actionType, instance, method, unrollFactor)!;
private static readonly MethodInfo FallbackSignature = new Action(BenchmarkActionBase.OverheadStatic).GetMethodInfo();
public static IBenchmarkAction CreateWorkload(IBenchmarkActionFactory? factory, Descriptor descriptor, object instance, int unrollFactor, bool consumeTasksSynchronously = false) =>
CreateCore(factory, instance, descriptor.WorkloadMethod, unrollFactor, consumeTasksSynchronously);
public static IBenchmarkAction CreateOverhead(IBenchmarkActionFactory? factory, Descriptor descriptor, object instance, int unrollFactor) =>
CreateCore(factory, instance, FallbackSignature, unrollFactor);View on GitHub (pinned to b515068b61)
Solutions
- Change the benchmark method signature from 'async void' to 'async Task'.
- If the method cannot be changed, wrap the async void call in a synchronous method that blocks on a Task.
When it happens
Trigger: Thrown at src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/BenchmarkActionFactory.cs:122 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/818163b588734cf9.
Report an issue: GitHub.