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

Resolve net core shared nullability #85

Merged
merged 2 commits into from
Aug 20, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Main_GoodArgs_DownloadFile()
{
Assert.AreEqual(0, Program.Main(args));
}
catch (AggregateException exception) when(exception.InnerException.GetType() == typeof(System.Net.Http.HttpRequestException))
catch (AggregateException exception) when(exception.InnerException?.GetType() == typeof(System.Net.Http.HttpRequestException))
{
Assert.Inconclusive("Unable to download the file. Check your Internet connection.");
}
Expand Down
31 changes: 16 additions & 15 deletions src/Shared/NetCore.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System;
using System.Reflection;

public class NetCore
{
public static string GetNetCoreVersion()
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];
throw new Exception("Unable to determine .NET Core version.");
}
}
using System;
using System.Reflection;

public class NetCore
{
public static string GetNetCoreVersion()
{
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyCodeBase = assembly.CodeBase ?? throw new ArgumentNullException("assemblyCodeBase");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct exception type since "assemblyCodeBase" is not an argument. I would suggest using an InvalidOperationException.

string[] assemblyPath = assemblyCodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is the same as it was. But this code fails on *nix systems if Microsoft.NETCore.App is installed at the root.
"/Microsoft.NETCore.App"

return assemblyPath[netCoreAppIndex + 1];
throw new Exception("Unable to determine .NET Core version.");
}
}