Update `RuntimeEnvironment.GetSystemVersion()` (#89575)
authorAaron Robinson <arobins@microsoft.com>
Thu, 27 Jul 2023 20:05:21 +0000 (13:05 -0700)
committerGitHub <noreply@github.com>
Thu, 27 Jul 2023 20:05:21 +0000 (13:05 -0700)
This API is now emitting a valid version in alignment with
https://github.com/dotnet/runtime/issues/28788.
---------
Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs
src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs

index 597c0a0..ddb1481 100644 (file)
@@ -34,6 +34,6 @@ namespace System.Runtime.InteropServices
         [Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
         public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) => throw new PlatformNotSupportedException();
 
-        public static string GetSystemVersion() => typeof(object).Assembly.ImageRuntimeVersion;
+        public static string GetSystemVersion() => $"v{Environment.Version}";
     }
 }
index 159cd52..a3afe89 100644 (file)
@@ -17,7 +17,8 @@ namespace System.Runtime.InteropServices
         [Fact]
         public void RuntimeEnvironmentSysVersion()
         {
-            Assert.NotEmpty(RuntimeEnvironment.GetSystemVersion());
+            // The historical format of this API is "vX.Y.Z", so we validate and retain that.
+            Assert.Equal($"v{Environment.Version}", RuntimeEnvironment.GetSystemVersion());
         }
 
 #pragma warning disable SYSLIB0019 // RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.