Skip to content

Commit 77c0980

Browse files
committed
Fix unhandled exception during test discovery on macOS
While debugging #29029 I noticed that we hit an unhandled exception because later macOS versions don't have an extra dot in the RID version number so the string split failed. Switched to using float parsing for the version like we do for Ubuntu.
1 parent cba19e6 commit 77c0980

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Tests/Microsoft.NET.TestFramework/EnvironmentInfo.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ public static bool SupportsTargetFramework(string targetFramework)
125125
{
126126
string restOfRid = currentRid.Substring(ridOS.Length + 1);
127127
string ubuntuVersionString = restOfRid.Split('-')[0];
128-
if (float.TryParse(ubuntuVersionString, out float ubuntuVersion))
128+
if (float.TryParse(ubuntuVersionString, System.Globalization.CultureInfo.InvariantCulture, out float ubuntuVersion))
129129
{
130-
if (ubuntuVersion > 16.04)
130+
if (ubuntuVersion > 16.04f)
131131
{
132132
if (nugetFramework.Version < new Version(2, 0, 0, 0))
133133
{
@@ -144,27 +144,25 @@ public static bool SupportsTargetFramework(string targetFramework)
144144
{
145145
string restOfRid = currentRid.Substring(ridOS.Length + 1);
146146
string osxVersionString = restOfRid.Split('-')[0];
147-
// From a string such as "10.14", get the second part, e.g. "14"
148-
string osxVersionString2 = osxVersionString.Split('.')[1];
149-
if (int.TryParse(osxVersionString2, out int osxVersion))
147+
if (float.TryParse(osxVersionString, System.Globalization.CultureInfo.InvariantCulture, out float osxVersion))
150148
{
151149
// .NET Core 1.1 - 10.11, 10.12
152150
// .NET Core 2.0 - 10.12+
153-
if (osxVersion <= 11)
151+
if (osxVersion <= 10.11f)
154152
{
155153
if (nugetFramework.Version >= new Version(2, 0, 0, 0))
156154
{
157155
return false;
158156
}
159157
}
160-
else if (osxVersion == 12)
158+
else if (osxVersion == 10.12f)
161159
{
162160
if (nugetFramework.Version < new Version(2, 0, 0, 0))
163161
{
164162
return false;
165163
}
166164
}
167-
else if (osxVersion > 12)
165+
else if (osxVersion > 10.12f)
168166
{
169167
// .NET Core 2.0 is out of support, and doesn't seem to work with OS X 10.14
170168
// (it finds no assets for the RID), even though the support page says "10.12+"

0 commit comments

Comments
 (0)