Skip to content

Commit

Permalink
Fixed null ref in diagnosis
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Jun 13, 2022
1 parent 11c3a01 commit 5ce4e18
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Elmah.Io.Cli/DiagnoseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,17 @@ private static Dictionary<string, string> FindPackages(FileInfo packageFile)
return itemGroups
.SelectMany(ig => ig
.Elements(ns + "PackageReference")
.Where(pr => pr.Attribute("Include").Value.StartsWith("Elmah.Io")))
.ToDictionary(pr => pr.Attribute("Include").Value, pr => pr.Attribute("Version").Value);
.Where(pr => pr.Attribute("Include") != null && pr.Attribute("Include").Value.StartsWith("Elmah.Io")))
.ToDictionary(pr => pr.Attribute("Include").Value, pr => pr.Attribute("Version") != null ? pr.Attribute("Version").Value : null);
}

private static void DiagnosePackageVersion(Dictionary<string, string> packagesFound, params string[] packageNames)
{
foreach (var packageName in packageNames)
{
var packageVersion = packagesFound[packageName];
if (string.IsNullOrWhiteSpace(packageVersion)) continue;

if (packageVersion.StartsWith("1."))
ReportError("An old 1.x package is referenced. Install the newest version from NuGet.");
else if (packageVersion.StartsWith("2."))
Expand Down

0 comments on commit 5ce4e18

Please sign in to comment.