From 79ff67de00d3f31a6db61f9247499ae86377cc46 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 29 Aug 2026 17:14:21 +1000 Subject: [PATCH] Resolve the OS platform on demand GetOsPlatform throws for any platform outside Linux, Windows, OSX, Android and iOS, and it ran from the Namer static constructor. VerifySettings creates a Namer, so on FreeBSD, browser-wasm or tvOS every verification failed with a TypeInitializationException, including the tests that never asked for UniqueForOSPlatform. It is now resolved by the property, which only PrefixUnique reads, and only when UniqueForOSPlatform is actually set. The message also names the platform now, since 'Unknown OS' gave nothing to act on. --- src/Verify/Naming/Namer.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Verify/Naming/Namer.cs b/src/Verify/Naming/Namer.cs index 2e5e1fc62f..fc0fb29906 100644 --- a/src/Verify/Naming/Namer.cs +++ b/src/Verify/Naming/Namer.cs @@ -151,7 +151,6 @@ static Namer() Architecture = RuntimeInformation .ProcessArchitecture.ToString() .ToLowerInvariant(); - OperatingSystemPlatform = GetOsPlatform(); } static string GetOsPlatform() @@ -181,7 +180,7 @@ static string GetOsPlatform() return "IOS"; } - throw new("Unknown OS"); + throw new($"Unknown OS: {RuntimeInformation.OSDescription}. UniqueForOSPlatform cannot name this platform."); } public static string Runtime { get; } @@ -190,7 +189,16 @@ static string GetOsPlatform() public static string Architecture { get; } - public static string OperatingSystemPlatform { get; } + static string? operatingSystemPlatform; + + /// + /// Resolved on demand rather than in the static constructor. GetOsPlatform throws for + /// any platform outside the handful it names, and VerifySettings creates a Namer, so + /// resolving eagerly failed every verification on an unrecognized platform + /// (FreeBSD, browser-wasm, tvOS) with a TypeInitializationException, even for tests + /// that never asked for UniqueForOSPlatform. + /// + public static string OperatingSystemPlatform => operatingSystemPlatform ??= GetOsPlatform(); internal Namer() {