diff --git a/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs b/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs index 8f4e7222c..13a3a42cd 100644 --- a/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs +++ b/src/Chapter05.Tests/Listing05.12.PassingCommandLineArgumentsToMain.Tests.cs @@ -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."); } diff --git a/src/Shared/NetCore.cs b/src/Shared/NetCore.cs index 440fbe376..4fac3bf0d 100644 --- a/src/Shared/NetCore.cs +++ b/src/Shared/NetCore.cs @@ -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"); + string[] assemblyPath = assemblyCodeBase.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."); + } +}