Skip to content

Fix NRE opening Solution PM UI for many projects caused by race condition - #7686

Merged
donnie-msft merged 1 commit into
devfrom
dev-donnie-msft-pmuiNre
Sep 8, 2026
Merged

donnie-msft merged 1 commit into
devfrom
dev-donnie-msft-pmuiNre

Conversation

@donnie-msft

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#15073

Description

Opening the Solution Package Manager UI (PM UI) in a solution with many projects could intermittently fail with an error bar and a NullReferenceException in the output window, originating at VSSolutionManager.GetNuGetProjectsAsync.

Root cause:

  • InitializationTask was a shared field meant to be a shared signal meaning "an initialization is currently in progress, and callers should wait on it".
  • null meant no initialization is running right now
  • A task value mean initialization is in progress

The InitializationTask sentinel existed so an external consumer could observe an in-flight initialization and await it.
That consumer (in PackageItemLoader) was removed in 2020 by 6aeb27caae5 ("PM UI: enable CodeSpaces support", #3649).
Since then the field has been written but never read — dead code for ~6 years.
The real, idempotent initialization is already handled by EnsureInitializeAsync(), so the field adds nothing but risk.

Fix

Solution PM UI uses this task per project, via NuGetPackageSearchService.GetAllPackageFoldersAsync.

  • Issue is, one invocation can execute InitializationTask = null in the window between another invocation's assignment
  • We could fix that by awaiting on the local field, not the shared InitializationTask.
  • Even better, we can remove the shared field entirely because its consumers were removed in Enable codespaces support for NuGet PM UI #3649!

No behavior is lost, initialization is still awaited, just without the racy shared sentinel value.

Validation

Used https://github.com/OrchardCMS/OrchardCore (200+ projects) which repro'd for me in the Issue, but did not repro after several trials using this fix.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests behavior-preserving dead-code/race removal. The concurrency race isn't practical to cover with a deterministic unit test.
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@donnie-msft
donnie-msft requested a review from a team as a code owner September 4, 2026 20:54
@donnie-msft
donnie-msft merged commit 5955c01 into dev Sep 8, 2026
18 checks passed
@donnie-msft
donnie-msft deleted the dev-donnie-msft-pmuiNre branch September 8, 2026 16:53
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.

Opening Package Manager UI with many projects can error with "Object reference not set to an instance of an object"

3 participants