Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix null reference exception when it's not possible to get runtime version from the assembly #851

Merged
merged 6 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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