From 7938c9b6d05daa02b974702b2b6b76e049b404b1 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Mon, 28 Apr 2025 17:44:33 -0700 Subject: [PATCH 1/3] Fix a coup[e potential NullRefs in dotnet detector --- .../dotnet/DotNetComponentDetector.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs index dc673680e..f5af9aef2 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs @@ -138,9 +138,12 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID { var lockFile = this.lockFileFormat.Read(processRequest.ComponentStream.Stream, processRequest.ComponentStream.Location); - if (lockFile.PackageSpec is null) + if (lockFile.PackageSpec is null || lockFile.PackageSpec.RestoreMetadata is null) { - this.Logger.LogWarning("Lock file {LockFilePath} does not contain a PackageSpec.", processRequest.ComponentStream.Location); + // The lock file is not valid, or does not contain a PackageSpec. + // This could be due to the lock file being generated by a different version of the SDK. + // We should not fail the detector, but we should log a warning. + this.Logger.LogWarning("Lock file {LockFilePath} does not contain project information.", processRequest.ComponentStream.Location); return; } @@ -181,7 +184,7 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID var targetType = this.GetProjectType(projectOutputPath, projectName, cancellationToken); var componentReporter = this.ComponentRecorder.CreateSingleFileComponentRecorder(projectPath); - foreach (var target in lockFile.Targets) + foreach (var target in lockFile.Targets ?? []) { var targetFramework = target.TargetFramework?.GetShortFolderName(); From a00e59f7ae1fbb996d71f75a298864ff8f8a2b44 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Mon, 28 Apr 2025 17:46:39 -0700 Subject: [PATCH 2/3] Promote DotNet detector --- .../Experiments/DotNetDetectorExperiment.cs | 22 ------------------- .../Extensions/ServiceCollectionExtensions.cs | 1 - 2 files changed, 23 deletions(-) delete mode 100644 src/Microsoft.ComponentDetection.Orchestrator/Experiments/DotNetDetectorExperiment.cs diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Experiments/DotNetDetectorExperiment.cs b/src/Microsoft.ComponentDetection.Orchestrator/Experiments/DotNetDetectorExperiment.cs deleted file mode 100644 index ab0c33de3..000000000 --- a/src/Microsoft.ComponentDetection.Orchestrator/Experiments/DotNetDetectorExperiment.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Microsoft.ComponentDetection.Orchestrator.Experiments.Configs; - -using Microsoft.ComponentDetection.Contracts; -using Microsoft.ComponentDetection.Detectors.DotNet; - -/// -/// Validating the . -/// -public class DotNetDetectorExperiment : IExperimentConfiguration -{ - /// - public string Name => "DotNetDetector"; - - /// - public bool IsInControlGroup(IComponentDetector componentDetector) => false; - - /// - public bool IsInExperimentGroup(IComponentDetector componentDetector) => componentDetector is DotNetComponentDetector; - - /// - public bool ShouldRecord(IComponentDetector componentDetector, int numComponents) => true; -} diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs index 306199b56..7f097fb90 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs @@ -66,7 +66,6 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); // Detectors // CocoaPods From 70ee94930c2f7d9b690db554452656f3fb6bf67e Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Tue, 29 Apr 2025 07:58:05 -0700 Subject: [PATCH 3/3] Remove IExperimentalDetector --- .../dotnet/DotNetComponentDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs index f5af9aef2..48bafd9e8 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs @@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Detectors.DotNet; using Microsoft.ComponentDetection.Contracts.TypedComponent; using Microsoft.Extensions.Logging; -public class DotNetComponentDetector : FileComponentDetector, IExperimentalDetector +public class DotNetComponentDetector : FileComponentDetector { private const string GlobalJsonFileName = "global.json"; private readonly ICommandLineInvocationService commandLineInvocationService;