Skip to content

Commit af7d049

Browse files
Update RuntimeEnvironment.GetSystemVersion() (dotnet#89575)
This API is now emitting a valid version in alignment with dotnet#28788. --------- Co-authored-by: Stephen Toub <[email protected]>
1 parent b4357e1 commit af7d049

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public static string GetRuntimeDirectory()
3434
[Obsolete(Obsoletions.RuntimeEnvironmentMessage, DiagnosticId = Obsoletions.RuntimeEnvironmentDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
3535
public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) => throw new PlatformNotSupportedException();
3636

37-
public static string GetSystemVersion() => typeof(object).Assembly.ImageRuntimeVersion;
37+
public static string GetSystemVersion() => $"v{Environment.Version}";
3838
}
3939
}

src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public void RuntimeEnvironmentRuntimeDirectory()
1717
[Fact]
1818
public void RuntimeEnvironmentSysVersion()
1919
{
20-
Assert.NotEmpty(RuntimeEnvironment.GetSystemVersion());
20+
// The historical format of this API is "vX.Y.Z", so we validate and retain that.
21+
Assert.Equal($"v{Environment.Version}", RuntimeEnvironment.GetSystemVersion());
2122
}
2223

2324
#pragma warning disable SYSLIB0019 // RuntimeEnvironment members SystemConfigurationFile, GetRuntimeInterfaceAsIntPtr, and GetRuntimeInterfaceAsObject are no longer supported and throw PlatformNotSupportedException.

0 commit comments

Comments
 (0)