Skip to content

Commit

Permalink
fix: catch exception when .net core version cannot be determined (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda authored May 23, 2023
1 parent 1a90a65 commit e3be209
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Box.V2/Managers/BoxResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,21 @@ private string CheckFor462PlusVersion(int releaseKey)

private string GetNetCoreVersion()
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
if (assembly?.CodeBase != null)
try
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
if (assembly?.CodeBase != null)
{
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
var netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
return netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2 ?
assemblyPath[netCoreAppIndex + 1] :
null;
}
}
catch
{
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
var netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
return netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2 ?
assemblyPath[netCoreAppIndex + 1] :
null;
return null;
}

#if NETSTANDARD2_0
Expand Down

0 comments on commit e3be209

Please sign in to comment.