Skip to content

Commit e3be209

Browse files
authored
fix: catch exception when .net core version cannot be determined (#906)
1 parent 1a90a65 commit e3be209

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Box.V2/Managers/BoxResourceManager.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,21 @@ private string CheckFor462PlusVersion(int releaseKey)
356356

357357
private string GetNetCoreVersion()
358358
{
359-
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
360-
if (assembly?.CodeBase != null)
359+
try
360+
{
361+
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
362+
if (assembly?.CodeBase != null)
363+
{
364+
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
365+
var netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
366+
return netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2 ?
367+
assemblyPath[netCoreAppIndex + 1] :
368+
null;
369+
}
370+
}
371+
catch
361372
{
362-
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
363-
var netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
364-
return netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2 ?
365-
assemblyPath[netCoreAppIndex + 1] :
366-
null;
373+
return null;
367374
}
368375

369376
#if NETSTANDARD2_0

0 commit comments

Comments
 (0)