{"record":{"id":"e0184e0ca09a9d7e","repo":"dotnet/BenchmarkDotNet","slug":"runtime-not-supported","errorCode":null,"errorMessage":"Runtime not supported","messagePattern":"Runtime not supported","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs","lineNumber":113,"sourceCode":"\n                    return CsProjCoreToolchain.From(new NetCoreAppSettings(coreRuntime.MsBuildMoniker, coreRuntime.Name));\n\n                case NativeAotRuntime nativeAotRuntime:\n                    return nativeAotRuntime.RuntimeMoniker != RuntimeMoniker.NotRecognized\n                            ? GetToolchain(nativeAotRuntime.RuntimeMoniker)\n                            : NativeAotToolchain.CreateBuilder().UseNuGet().TargetFrameworkMoniker(nativeAotRuntime.MsBuildMoniker).ToToolchain();\n\n                case WasmRuntime wasmRuntime:\n                    return WasmToolchain.From(new NetCoreAppSettings(targetFrameworkMoniker: wasmRuntime.MsBuildMoniker, name: wasmRuntime.Name));\n\n                case R2RRuntime r2rRuntime:\n                    if (r2rRuntime.RuntimeMoniker != RuntimeMoniker.NotRecognized)\n                        return GetToolchain(r2rRuntime.RuntimeMoniker);\n\n                    return CsProjCoreToolchain.From(new NetCoreAppSettings(r2rRuntime.MsBuildMoniker, r2rRuntime.Name));\n\n                default:\n                    throw new ArgumentOutOfRangeException(nameof(runtime), runtime, \"Runtime not supported\");\n            }\n        }\n\n        private static IToolchain GetToolchain(RuntimeMoniker runtimeMoniker)\n        {\n            switch (runtimeMoniker)\n            {\n                case RuntimeMoniker.Net461:\n                    return CsProjClassicNetToolchain.Net461;\n\n                case RuntimeMoniker.Net462:\n                    return CsProjClassicNetToolchain.Net462;\n\n                case RuntimeMoniker.Net47:\n                    return CsProjClassicNetToolchain.Net47;\n\n                case RuntimeMoniker.Net471:\n                    return CsProjClassicNetToolchain.Net471;","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs#L95-L131","documentation":"Thrown by the public GetToolchain(Runtime runtime, ...) overload when the runtime object's concrete type is none of the six handled switch cases (ClrRuntime, MonoRuntime, CoreRuntime, NativeAotRuntime, WasmRuntime, R2RRuntime). BDN dispatches toolchain selection by runtime type, and any unrecognized type — including custom Runtime subclasses or null in some edge paths — falls through to the default and raises ArgumentOutOfRangeException. This is reached only when no explicit toolchain is set on the Job (otherwise TryGetToolchain short-circuits).","triggerScenarios":"ToolchainExtensions.GetToolchain(Runtime, Descriptor?, bool, bool) is called for a BenchmarkCase or Job whose Runtime is a type outside the six known types. Entry points: benchmarkCase.GetToolchain() (line 21) and job.GetToolchain() (line 31), both of which only call this when the Job does not have an explicit toolchain. A custom Runtime subclass, a third-party runtime type, or a Runtime from an incompatible BDN assembly version triggers the default branch.","commonSituations":"Subclassing Runtime to model a bespoke environment and expecting BDN to pick a toolchain. Mixing BDN versions where a runtime type from a newer assembly is passed to an older BDN. A null Runtime returned by a misconfigured EnvironmentResolver. A renamed/removed runtime type after a major BDN upgrade.","solutions":["Provide an explicit toolchain on the Job via .WithToolchain(yourToolchain) so GetToolchain never dispatches by runtime type (TryGetToolchain short-circuits at line 22/32)","Use one of the built-in Runtime types (CoreRuntime, ClrRuntime, MonoRuntime, NativeAotRuntime, WasmRuntime, R2RRuntime) instead of a custom subclass","If you need a custom runtime, upgrade/align BDN to a version where your runtime type is handled, or contribute a case to the switch"],"exampleFix":"// before\npublic class MyCustomRuntime : Runtime { /* ... */ }\n\nvar job = Job.Default.WithRuntime(new MyCustomRuntime());\n// => ArgumentOutOfRangeException: Runtime not supported\n\n// after (explicit toolchain — recommended for custom runtimes)\nvar job = Job.Default\n    .WithRuntime(new MyCustomRuntime())\n    .WithToolchain(CsProjCoreToolchain.From(\n        new NetCoreAppSettings(\"net8.0\", \"MyCustom\")));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Guard the runtime before BDN dispatches a toolchain by type.\nusing BenchmarkDotNet.Environments;\n\nstatic bool IsKnownRuntime(Runtime? r) => r is ClrRuntime or CoreRuntime or MonoRuntime\n    or NativeAotRuntime or WasmRuntime or R2RRuntime;\n\nif (!IsKnownRuntime(job.ResolveValue(EnvironmentMode.RuntimeCharacteristic, EnvironmentResolver.Instance)))\n    throw new InvalidOperationException(\n        \"Runtime type is not handled by BDN's toolchain dispatcher; set an explicit toolchain via .WithToolchain(...).\");","tryCatchPattern":"try { BenchmarkRunner.Run<MyBench>(); }\ncatch (ArgumentOutOfRangeException ex) when (ex.Message.Contains(\"Runtime not supported\"))\n{\n    throw new InvalidOperationException(\n        \"The configured Runtime type has no built-in toolchain. Set one explicitly with .WithToolchain(...).\", ex);\n}","preventionTips":["For any custom or unusual runtime, always set an explicit toolchain on the Job with .WithToolchain(...) so BDN never dispatches by runtime type.","Avoid subclassing Runtime for ad-hoc environments; model them through the built-in Runtime types and a custom toolchain instead.","Keep the BDN Environments and Toolchains assemblies version-aligned so every runtime type has a matching switch case."],"tags":["toolchain","runtime","dispatch","argument-out-of-range","configuration"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}