From ea38bf5ebc41ff49970cab0efffb5ab988641a92 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Thu, 7 Mar 2024 15:35:06 +0100 Subject: [PATCH] C#: Improve `global.json` file parsing --- .../Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs index f0220b6be749..41a117ed5d8d 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs @@ -131,11 +131,16 @@ private static BuildScript DownloadDotNet(IBuildActions actions, ILogger logger, try { var o = JObject.Parse(File.ReadAllText(path)); - versions.Add((string)o?["sdk"]?["version"]!); + var v = (string?)o?["sdk"]?["version"]; + if (v is not null) + { + versions.Add(v); + } } catch { // not a valid `global.json` file + logger.LogInfo($"Couldn't find .NET SDK version in '{path}'."); continue; } }