Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b6aa0e6

Browse files
committed
Better handling of VersionId being missing.
1 parent 7009256 commit b6aa0e6

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/managed/Microsoft.DotNet.PlatformAbstractions/Native/PlatformApis.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,8 @@ private static DistroInfo LoadDistroInfo()
128128
// are backwards compatible.
129129
private static DistroInfo NormalizeDistroInfo(DistroInfo distroInfo)
130130
{
131-
if (string.IsNullOrEmpty(distroInfo.VersionId))
132-
{
133-
// Some distribution does not have VERSION_ID defined.
134-
// Since we need it, we workaround this by giving it the value "unavailable".
135-
distroInfo.VersionId = "unavailable";
136-
}
137-
138-
int minorVersionNumberSeparatorIndex = distroInfo.VersionId.IndexOf('.');
131+
// Handle if VersionId is null by just setting the index to -1.
132+
int minorVersionNumberSeparatorIndex = distroInfo.VersionId?.IndexOf('.') ?? -1;
139133

140134
if (distroInfo.Id == "rhel" && minorVersionNumberSeparatorIndex != -1)
141135
{

src/managed/Microsoft.DotNet.PlatformAbstractions/RuntimeEnvironment.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ private static string GetRIDVersion()
5252
case Platform.Windows:
5353
return GetWindowsProductVersion();
5454
case Platform.Linux:
55+
if (string.IsNullOrEmpty(OperatingSystemVersion))
56+
{
57+
return string.Empty;
58+
}
59+
5560
return $".{OperatingSystemVersion}";
5661
case Platform.Darwin:
5762
return $".{OperatingSystemVersion}";

0 commit comments

Comments
 (0)