From 03c4f2a71b12a65a849c71537ce7ef87c0b981a2 Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Thu, 27 Jul 2023 09:00:39 -0700 Subject: [PATCH 1/3] Update RuntimeEnvironment.GetSystemVersion() This API is now emitting a valid version in alignment with https://github.com/dotnet/runtime/issues/28788. --- .../src/System/Runtime/InteropServices/RuntimeEnvironment.cs | 2 +- .../System/Runtime/InteropServices/RuntimeEnvironmentTests.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs index 597c0a0054c71c..97376413aff464 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs +++ b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs @@ -34,6 +34,6 @@ public static string GetRuntimeDirectory() [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; } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs index 159cd5266da484..a3afe89647774b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs @@ -17,7 +17,8 @@ public void RuntimeEnvironmentRuntimeDirectory() [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. From c3d9112ca0424c510724fdac2c2b0606efe2e4fc Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Thu, 27 Jul 2023 09:32:41 -0700 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Stephen Toub --- .../src/System/Runtime/InteropServices/RuntimeEnvironment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs index 97376413aff464..e2eb6adcc5e210 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs +++ b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs @@ -34,6 +34,6 @@ public static string GetRuntimeDirectory() [Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) => throw new PlatformNotSupportedException(); - public static string GetSystemVersion() => "v" + Environment.Version; + public static string GetSystemVersion() => $"v{Environment.Version}; } } From 7c00d32e2293c107fa289109579d59b5d3b36bcb Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Thu, 27 Jul 2023 09:47:41 -0700 Subject: [PATCH 3/3] Update src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs --- .../src/System/Runtime/InteropServices/RuntimeEnvironment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs index e2eb6adcc5e210..ddb1481aafa760 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs +++ b/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs @@ -34,6 +34,6 @@ public static string GetRuntimeDirectory() [Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) => throw new PlatformNotSupportedException(); - public static string GetSystemVersion() => $"v{Environment.Version}; + public static string GetSystemVersion() => $"v{Environment.Version}"; } }