{"record":{"id":"d0409fe301a41b8c","repo":"dotnet/BenchmarkDotNet","slug":"default-benchmarkactionfactory-only-supports-void","errorCode":null,"errorMessage":"Default BenchmarkActionFactory only supports void* return, not T*","messagePattern":"Default BenchmarkActionFactory only supports void\\* return, not T\\*","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/BenchmarkActionFactory.cs","lineNumber":126,"sourceCode":"            unrollFactor);\n    }\n\n    private static void PrepareInstanceAndResultType(object instance, MethodInfo targetMethod, out object? resultInstance, out Type resultType)\n    {\n        resultInstance = targetMethod.IsStatic ? null : instance;\n        resultType = targetMethod.ReturnType;\n\n        if (resultType == typeof(void))\n        {\n            // DONTTOUCH: async should be checked for target method\n            // as fallbackIdleSignature used for result type detection only.\n            bool isUsingAsyncKeyword = targetMethod?.HasAttribute<AsyncStateMachineAttribute>() ?? false;\n            if (isUsingAsyncKeyword)\n                throw new NotSupportedException(\"Async void is not supported by design.\");\n        }\n        else if (resultType.IsPointer && resultType != typeof(void*))\n        {\n            throw new NotSupportedException($\"Default {nameof(BenchmarkActionFactory)} only supports void* return, not T*\");\n        }\n    }\n\n    /// <summary>Helper to enforce .ctor signature.</summary>\n    private static BenchmarkActionBase Create(Type actionType, object? instance, MethodInfo method, int unrollFactor) =>\n        (BenchmarkActionBase)Activator.CreateInstance(actionType, instance, method, unrollFactor)!;\n\n    private static readonly MethodInfo FallbackSignature = new Action(BenchmarkActionBase.OverheadStatic).GetMethodInfo();\n\n    public static IBenchmarkAction CreateWorkload(IBenchmarkActionFactory? factory, Descriptor descriptor, object instance, int unrollFactor, bool consumeTasksSynchronously = false) =>\n        CreateCore(factory, instance, descriptor.WorkloadMethod, unrollFactor, consumeTasksSynchronously);\n\n    public static IBenchmarkAction CreateOverhead(IBenchmarkActionFactory? factory, Descriptor descriptor, object instance, int unrollFactor) =>\n        CreateCore(factory, instance, FallbackSignature, unrollFactor);\n\n    public static IBenchmarkAction CreateGlobalSetup(IBenchmarkActionFactory? factory, Descriptor descriptor, object instance) =>\n        CreateCore(factory, instance, descriptor.GlobalSetupMethod ?? FallbackSignature, 1);\n","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/BenchmarkActionFactory.cs#L108-L144","documentation":"The default InProcess NoEmit BenchmarkActionFactory supports void* returns for unsafe benchmarks but cannot marshal typed pointers T*; it throws NotSupportedException for them.","triggerScenarios":"Thrown at src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/BenchmarkActionFactory.cs:126 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Return void* from the unsafe benchmark method, or change the return type to a supported managed type.","If you need the pointer value, return IntPtr or nint instead of a typed pointer.","Provide a custom BenchmarkActionFactory to handle T* returns."],"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"}