From e3be209b20a5c323f547d7634663883613959180 Mon Sep 17 00:00:00 2001 From: mwwoda <84077698+mwwoda@users.noreply.github.com> Date: Tue, 23 May 2023 15:35:09 +0200 Subject: [PATCH] fix: catch exception when .net core version cannot be determined (#906) --- Box.V2/Managers/BoxResourceManager.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Box.V2/Managers/BoxResourceManager.cs b/Box.V2/Managers/BoxResourceManager.cs index c05d3a982..32bfa59ae 100644 --- a/Box.V2/Managers/BoxResourceManager.cs +++ b/Box.V2/Managers/BoxResourceManager.cs @@ -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