Skip to content

NullReferenceException when LockFileUtilities.GetLockFile returns null; error reason silently swallowed #740

Closed

Description

@tymarats

ProjectAnalysisService.AnalyzeProjectAsync calls LockFileUtilities.GetLockFile(lockFilePath, NullLogger.Instance) and later on dereferences the result without a null check.

GetLockFile can return null for several reasons, and when that happens the tool crashes with a bare NullReferenceException further down, where lockFile.Targets is accessed:

  Discovering projects...
  Analyzing project(s)...
  Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
     at DotNetOutdated.Core.Services.ProjectAnalysisService.AnalyzeProjectAsync(String projectPath, Boolean runRestore, Boolean includeTransitiveDependencies, Int32
  transitiveDepth, String runtime) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated.Core/Services/ProjectAnalysisService.cs:line 56
     at DotNetOutdated.Program.<>c__DisplayClass98_0.<<OnExecute>b__0>d.MoveNext() in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated/Program.cs:line 209
...

The actionable problem isn't only the NRE--it's that the reason GetLockFile failed is not surfaced. The NuGet lock-file reader writes diagnostics through the ILogger it's given, but the call site passes NullLogger.Instance, so any warning or error that might have explained the failure is discarded. The user is left with no clue what happened exactly.

Two things should change:

  1. Pass a real ILogger to GetLockFile so any underlying reason (when one is logged at all--it isn't always) reaches the user.
  2. Null-check the returned LockFile and throw a clear, contextual exception (or skip the project) instead of letting the NRE propagate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions