{"record":{"id":"8f1c8b043b727d0c","repo":"dotnet/BenchmarkDotNet","slug":"platform-platform-is-not-supported","errorCode":null,"errorMessage":"Platform {platform} is not supported","messagePattern":"Platform (.+?) is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Attributes/Filters/OperatingSystemsFilterAttribute.cs","lineNumber":52,"sourceCode":"            }))\n        {\n        }\n\n        // OSPlatform is a struct so it can not be used as attribute argument and this is why we use PlatformID enum\n        private static OSPlatform Map(OS platform)\n        {\n            switch (platform)\n            {\n                case OS.Windows:\n                    return OSPlatform.Windows;\n                case OS.Linux:\n                    return OSPlatform.Linux;\n                case OS.macOS:\n                    return OSPlatform.OSX;\n                case OS.Browser:\n                    return browser;\n                default:\n                    throw new NotSupportedException($\"Platform {platform} is not supported\");\n            }\n        }\n    }\n}","sourceCodeStart":34,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Attributes/Filters/OperatingSystemsFilterAttribute.cs#L34-L56","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["If you are constructing the OS value from external input, validate it against the known members (OS.Windows/Linux/macOS/Browser) before use.","Avoid casting raw integers to OS; use the named enum members or an explicit mapping table.","If extending the OS enum in a fork, add the matching case to Map() in OperatingSystemsFilterAttribute.cs:39.","Update BenchmarkDotNet to the latest released version if you suspect a stale build with an incomplete switch."],"exampleFix":"// before\nvar os = (OS) someByteFromConfig;\nvar attr = new OperatingSystemsFilterAttribute(true, os);\n\n// after\nif (!Enum.IsDefined(typeof(OS), someByteFromConfig))\n    throw new ArgumentOutOfRangeException(nameof(someByteFromConfig));\nvar os = (OS) someByteFromConfig;\nvar attr = new OperatingSystemsFilterAttribute(true, os);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(OS), osValue))\n    throw new ArgumentOutOfRangeException(nameof(osValue), $\"'{osValue}' is not a valid OS member\");\n// safe to use in new OperatingSystemsFilterAttribute(true, osValue);","typeGuard":"static bool IsValidOS(OS os) => Enum.IsDefined(typeof(OS), os);","tryCatchPattern":"try { var attr = new OperatingSystemsFilterAttribute(true, os); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Platform\"))\n{\n    // recover: fall back to no platform filter and log the bad value\n}","preventionTips":["Never cast raw integers/bytes to OS without Enum.IsDefined validation.","Prefer the named OS members over computed values.","When extending the OS enum, update OperatingSystemsFilterAttribute.Map in the same change."],"tags":["platform","enum","filter-attribute","notsupported"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}