Skip to content

Commit

Permalink
fix: fix null reference exception when it's not possible to get `runt…
Browse files Browse the repository at this point in the history
…ime` version from the assembly (#851)
  • Loading branch information
mwwoda authored Aug 24, 2022
1 parent 054d3e1 commit 77046fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 16 additions & 6 deletions Box.V2/Managers/BoxResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Box.V2.Managers
Expand Down Expand Up @@ -379,12 +380,21 @@ private string CheckFor45PlusVersion(int releaseKey)
private string GetNetCoreVersion()
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
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;
}
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;
}

#if NETSTANDARD2_0
var frameworkVersion = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
return Regex.Match(frameworkVersion, @"\d+(\.\d+)+").Value;
#else
return null;
#endif
}
}
}
6 changes: 5 additions & 1 deletion Box.V2/Request/HttpRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ private class ClientFactory

private static HttpClient CreateClient(bool followRedirect, IWebProxy webProxy)
{
var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip };
var handler = new HttpClientHandler();
if (handler.SupportsAutomaticDecompression)
{
handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
}
handler.AllowAutoRedirect = followRedirect;

if (webProxy != null)
Expand Down

0 comments on commit 77046fb

Please sign in to comment.