{"record":{"id":"efe75711046de9d4","repo":"dotnet/BenchmarkDotNet","slug":"asyncmethodbuilderattribute-not-found-on-type-asy","errorCode":null,"errorMessage":"AsyncMethodBuilderAttribute not found on type {asyncType.GetDisplayName()} from {Descriptor.DisplayInfo}","messagePattern":"AsyncMethodBuilderAttribute not found on type (.+?) from (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Toolchains/InProcess/Emit/Implementation/Emitters/AsyncCoreEmitterBase.cs","lineNumber":133,"sourceCode":"            return typeof(AsyncTaskMethodBuilder);\n\n            Type GetBuilderTypeFromUserSpecifiedAsyncType(Type asyncType)\n            {\n                if (asyncType.GetAsyncMethodBuilderAttribute() is { } typeAttr\n                    && typeAttr.GetType().GetProperty(nameof(AsyncMethodBuilderAttribute.BuilderType), BindingFlags.Public | BindingFlags.Instance)?.GetValue(typeAttr) is Type typeBuilderType)\n                {\n                    return GetConcreteBuilderType(typeBuilderType, asyncType);\n                }\n                // Task and Task<T> are not annotated with their builder type, the C# compiler special-cases them.\n                if (asyncType == typeof(Task))\n                {\n                    return typeof(AsyncTaskMethodBuilder);\n                }\n                if (asyncType.IsGenericType && asyncType.GetGenericTypeDefinition() == typeof(Task<>))\n                {\n                    return typeof(AsyncTaskMethodBuilder<>).MakeGenericType([asyncType.GetGenericArguments()[0]]);\n                }\n                throw new NotSupportedException($\"AsyncMethodBuilderAttribute not found on type {asyncType.GetDisplayName()} from {Descriptor.DisplayInfo}\");\n            }\n\n            static Type GetConcreteBuilderType(Type builderType, Type forReturnType)\n            {\n                if (!builderType.IsGenericTypeDefinition)\n                {\n                    return builderType;\n                }\n                if (builderType.GetGenericArguments().Length != 1)\n                {\n                    throw new NotSupportedException($\"AsyncMethodBuilder {builderType.GetDisplayName()} has generic arity greater than 1.\");\n                }\n                var resultType = forReturnType\n                    .GetMethod(nameof(Task.GetAwaiter), BindingFlags.Public | BindingFlags.Instance)!\n                    .ReturnType\n                    .GetMethod(nameof(TaskAwaiter.GetResult), BindingFlags.Public | BindingFlags.Instance)!\n                    .ReturnType;\n                return builderType.MakeGenericType([resultType]);","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Toolchains/InProcess/Emit/Implementation/Emitters/AsyncCoreEmitterBase.cs#L115-L151","documentation":"The InProcess async emitter locates the async method builder via AsyncMethodBuilderAttribute on the returned awaitable type; the attribute is missing on the type used by the benchmark.","triggerScenarios":"Thrown at src/BenchmarkDotNet/Toolchains/InProcess/Emit/Implementation/Emitters/AsyncCoreEmitterBase.cs:133 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make sure the workload returns a type annotated with AsyncMethodBuilderAttribute (Task, Task<T>, ValueTask, ValueTask<T>, or a custom task-like type that declares the attribute).","Reference a framework version where the returned async type carries AsyncMethodBuilderAttribute.","For custom task-like types, add [AsyncMethodBuilder(typeof(YourBuilder))] to the type."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}