dotnet/BenchmarkDotNet · error · NotSupportedException

You must specify the target framework moniker in explicit wa

Error message

You must specify the target framework moniker in explicit way using builder.TargetFrameworkMoniker(tfm) method

What it means

When the host process is not running on .NET Core, BenchmarkDotNet cannot infer the target framework moniker, so the custom dotnet CLI toolchain requires it to be specified explicitly.

Source

Thrown at src/BenchmarkDotNet/Toolchains/DotNetCli/CustomDotNetCliToolchainBuilder.cs:65

            return this;
        }

        /// <param name="targetFrameworkMoniker">TFM, example: net10.0</param>
        [PublicAPI]
        [SuppressMessage("ReSharper", "ParameterHidesMember")]
        public CustomDotNetCliToolchainBuilder TargetFrameworkMoniker(string targetFrameworkMoniker)
        {
            this.targetFrameworkMoniker = targetFrameworkMoniker ?? throw new ArgumentNullException(nameof(targetFrameworkMoniker));

            return this;
        }

        protected string GetTargetFrameworkMoniker()
        {
            if (targetFrameworkMoniker.IsNotBlank())
                return targetFrameworkMoniker;
            if (!Portability.RuntimeInformation.IsNetCore)
                throw new NotSupportedException("You must specify the target framework moniker in explicit way using builder.TargetFrameworkMoniker(tfm) method");

            return CoreRuntime.GetCurrentVersion().MsBuildMoniker;
        }

        /// <param name="newCustomDotNetCliPath">if not provided, the one from PATH will be used</param>
        [PublicAPI]
        public CustomDotNetCliToolchainBuilder DotNetCli(string newCustomDotNetCliPath)
        {
            if (newCustomDotNetCliPath.IsNotBlank() && !File.Exists(newCustomDotNetCliPath))
                throw new FileNotFoundException("Given file does not exist", newCustomDotNetCliPath);

            customDotNetCliPath = newCustomDotNetCliPath;

            return this;
        }

        /// <param name="newRuntimeIdentifier">if not provided, portable OS-arch will be used (example: "win-x64", "linux-x86")</param>
        [PublicAPI]

View on GitHub (pinned to b515068b61)

Solutions

  1. Call builder.TargetFrameworkMoniker(tfm) explicitly when building a custom toolchain on a non-.NET Core runtime.
  2. Run the benchmark host process on .NET (Core) so the current TFM can be detected automatically.

When it happens

Trigger: Thrown at src/BenchmarkDotNet/Toolchains/DotNetCli/CustomDotNetCliToolchainBuilder.cs:65 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/852e68216e492174. Report an issue: GitHub.