diff --git a/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dotnet/DotNetComponentDetector.cs index dc673680e..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; @@ -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(); 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