dotnet/BenchmarkDotNet · error · NotSupportedException

Platform {platform} is not supported

Error message

Platform {platform} is not supported

What it means

Thrown by the private Map(OS) helper inside OperatingSystemsFilterAttribute, which translates the library's own OS enum (Windows, Linux, macOS, Browser) into a System.Runtime.InteropServices.OSPlatform. The switch covers all four declared members and the default arm exists purely as an exhaustiveness guard. Because the OS enum is a closed byte enum with only four values, this exception is only reachable when a caller manufactures an out-of-range value.

Source

Thrown at src/BenchmarkDotNet/Attributes/Filters/OperatingSystemsFilterAttribute.cs:52

            }))
        {
        }

        // OSPlatform is a struct so it can not be used as attribute argument and this is why we use PlatformID enum
        private static OSPlatform Map(OS platform)
        {
            switch (platform)
            {
                case OS.Windows:
                    return OSPlatform.Windows;
                case OS.Linux:
                    return OSPlatform.Linux;
                case OS.macOS:
                    return OSPlatform.OSX;
                case OS.Browser:
                    return browser;
                default:
                    throw new NotSupportedException($"Platform {platform} is not supported");
            }
        }
    }
}

View on GitHub (pinned to b515068b61)

Solutions

  1. If you are constructing the OS value from external input, validate it against the known members (OS.Windows/Linux/macOS/Browser) before use.
  2. Avoid casting raw integers to OS; use the named enum members or an explicit mapping table.
  3. If extending the OS enum in a fork, add the matching case to Map() in OperatingSystemsFilterAttribute.cs:39.
  4. Update BenchmarkDotNet to the latest released version if you suspect a stale build with an incomplete switch.

Example fix

// before
var os = (OS) someByteFromConfig;
var attr = new OperatingSystemsFilterAttribute(true, os);

// after
if (!Enum.IsDefined(typeof(OS), someByteFromConfig))
    throw new ArgumentOutOfRangeException(nameof(someByteFromConfig));
var os = (OS) someByteFromConfig;
var attr = new OperatingSystemsFilterAttribute(true, os);
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(OS), osValue))
    throw new ArgumentOutOfRangeException(nameof(osValue), $"'{osValue}' is not a valid OS member");
// safe to use in new OperatingSystemsFilterAttribute(true, osValue);

Type guard

static bool IsValidOS(OS os) => Enum.IsDefined(typeof(OS), os);

Try / catch

try { var attr = new OperatingSystemsFilterAttribute(true, os); }
catch (NotSupportedException ex) when (ex.Message.Contains("Platform"))
{
    // recover: fall back to no platform filter and log the bad value
}

Prevention

When it happens

Trigger: Casting an arbitrary byte/int to OS (e.g. (OS)99) and passing it to the [OperatingSystemsFilterAttribute] constructor, or a future BDN version that adds a new OS member without updating this switch. The attribute arg itself must be a compile-time OS literal, so normal attribute usage can never hit it.

Common situations: Reflectively building filters with an unchecked (OS) cast, deserializing an OS value from config that is outside the 0-3 range, or running against a newer BDN build whose enum was extended but whose filter code was not.

Related errors


AI-assisted analysis of dotnet/BenchmarkDotNet@b515068b61 (2026-08-13). Data as JSON: /api/errors/8f1c8b043b727d0c. Report an issue: GitHub.