Visitar URL original
Fix NullReferenceException when GetLockFile returns null (#740) by tymarats · Pull Request #741 · dotnet-outdated/dotnet-outdated · GitHub
Skip to content

Fix NullReferenceException when GetLockFile returns null (#740) - #741

Merged
slang25 merged 1 commit into
dotnet-outdated:masterfrom
tymarats:fix/740-getlockfile-null
May 28, 2026
Merged

slang25 merged 1 commit into
dotnet-outdated:masterfrom
tymarats:fix/740-getlockfile-null

Conversation

@tymarats

Copy link
Copy Markdown
Contributor

Fixes #740.

ProjectAnalysisService.AnalyzeProjectAsync was passing
NullLogger.Instance to LockFileUtilities.GetLockFile and then
dereferencing the result without a null check, so any failure to
load project.assets.json surfaced as an opaque
NullReferenceException and the underlying NuGet diagnostic
(when one was emitted) was silently discarded.

Changes:

  • Pass an ILogger to GetLockFile so reader diagnostics reach the user.
  • Null-check the result and throw a contextual InvalidOperationException
  • Add a logger-aware constructor overload on ProjectAnalysisService;
    the existing 3-arg constructor is preserved (delegates with
    NullLogger.Instance) so the published DotNetOutdatedTool.Core
    library stays binary-compatible.
  • Register ILogger (as ConsoleLogger at LogLevel.Warning) in
    the CLI and MCP composition roots; MS.DI's greedy constructor
    selection then prefers the new overload. This is not ideal, but I
    could not find a better balance between the fix being "correct" and
    too noisy.

…ated#740)

Surface the underlying NuGet diagnostic by passing an ILogger to
LockFileUtilities.GetLockFile, and throw a contextual error instead
of a bare NRE when the lock file can't be loaded. Adds a logger-aware
constructor overload to keep DotNetOutdatedTool.Core API compatible.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes #740 by surfacing NuGet lock-file reader diagnostics and replacing an opaque NullReferenceException with a contextual InvalidOperationException when LockFileUtilities.GetLockFile returns null.

Changes:

  • Add an ILogger-aware constructor overload to ProjectAnalysisService (keeping the 3-arg ctor for binary compatibility) and pass the logger to GetLockFile, plus null-check its result.
  • Register ILogger as ConsoleLogger at LogLevel.Warning in the CLI composition root.
  • Register the same ILogger in the MCP composition root.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/DotNetOutdated.Core/Services/ProjectAnalysisService.cs Adds logger field/overload, forwards logger to GetLockFile, and throws contextual exception on null lock file.
src/DotNetOutdated/Program.cs Registers ConsoleLogger as ILogger in the CLI DI container.
src/DotNetOutdated/McpCommand.cs Registers ConsoleLogger as ILogger in the MCP DI container.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@slang25
slang25 merged commit 34e06d9 into dotnet-outdated:master May 28, 2026
1 check passed
@slang25 slang25 mentioned this pull request May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants