Fix opaque NullReferenceException when a NuGet V3 package version is missing (FD-440)#1994
Open
droyad wants to merge 1 commit into
Open
Fix opaque NullReferenceException when a NuGet V3 package version is missing (FD-440)#1994droyad wants to merge 1 commit into
droyad wants to merge 1 commit into
Conversation
…-440) When a requested package version doesn't exist on a NuGet V3 feed, the download failed with an opaque NullReferenceException thrown inside the (forked) NuGet.Commands SourceRepositoryDependencyProvider, which dereferences a null downloader returned for the absent version. Instead of going through that provider, NuGetV3LibDownloader now resolves the downloader from FindPackageByIdResource directly and null-checks it, throwing an actionable "version not found" error. This removes the buggy provider wrapper from the download path entirely; its throttle and ignore-failed-sources behaviour is irrelevant here, as Calamari passes no throttle and downloads from a single source. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
droyad
commented
Jun 5, 2026
Comment on lines
+42
to
+51
| var findPackageByIdResource = sourceRepository.GetResourceAsync<FindPackageByIdResource>(CancellationToken.None) | ||
| .GetAwaiter() | ||
| .GetResult(); | ||
|
|
||
| var packageIdentity = new PackageIdentity(packageId, version.ToNuGetVersion()); | ||
|
|
||
| string targetTempNupkg = Path.Combine(targetPath, Path.GetRandomFileName()); | ||
| var packageDownloader = providers.GetPackageDownloaderAsync(new PackageIdentity(packageId, version.ToNuGetVersion()), sourceCacheContext, logger, CancellationToken.None) | ||
| .GetAwaiter() | ||
| .GetResult(); | ||
| var packageDownloader = findPackageByIdResource.GetPackageDownloaderAsync(packageIdentity, sourceCacheContext, logger, CancellationToken.None) | ||
| .GetAwaiter() | ||
| .GetResult(); |
Contributor
Author
There was a problem hiding this comment.
The change is essentially pulling the core of the method shown in this PR inline and adding the null check here - this assumes the linked PR doesn't get merged.
3 tasks
bec-callow-oct
requested changes
Jun 9, 2026
| var packageDownloader = providers.GetPackageDownloaderAsync(new PackageIdentity(packageId, version.ToNuGetVersion()), sourceCacheContext, logger, CancellationToken.None) | ||
| .GetAwaiter() | ||
| .GetResult(); | ||
| var packageDownloader = findPackageByIdResource.GetPackageDownloaderAsync(packageIdentity, sourceCacheContext, logger, CancellationToken.None) |
Contributor
There was a problem hiding this comment.
I noticed sourceRepository.GetResourceAsync can return null, so we might need null handling for findPackageByIdResource as well
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Deploying with a package set to download on the target, from a NuGet V3 feed, for a version that doesn't exist on the feed, failed with an opaque
NullReferenceException— no hint that the real problem is a missing/unpublished version:Customer-facing context and the end-to-end product repro are in FD-440.
The problem is described in this PR for NuGet.Client. But since we don't want to add more things ot it, and the likelyhood of this getting fixed upstream in a timely manner are low, this PR avoids the problem.
Verification
Reproduced and fixed end-to-end on a local Octopus Server: a
Run a Scriptstep running on a worker pool, referencingNewtonsoft.Jsonversion9999.9.9(which doesn't exist) from a NuGet V3 feed (https://api.nuget.org/v3/index.json), with the package acquired on the worker.Before (stock Calamari) — bare NRE wrapped by the retry message:
After (this change) — clear, actionable message, no
NullReferenceExceptionanywhere in the log:Automated coverage: integration test
GivesActionableErrorWhenV3FeedIsMissingTheRequestedVersiondownloads a missing version fromapi.nuget.org— fails with the exact NRE above without this change, passes with it.On the retries: the download still retries all attempts before the deployment fails — left as-is intentionally. A version that's absent right now may legitimately be published to the feed mid-window (e.g. a lagging CI push), so retrying is the desired behaviour. This change only improves the message; it doesn't alter the retry policy.
Fixes FD-440