Skip to content

NuGet.Protocol nullability v2#7285

Draft
nkolev92 wants to merge 1 commit intodevfrom
dev-nkolev92-protocol2
Draft

NuGet.Protocol nullability v2#7285
nkolev92 wants to merge 1 commit intodevfrom
dev-nkolev92-protocol2

Conversation

@nkolev92
Copy link
Copy Markdown
Member

@nkolev92 nkolev92 commented Apr 15, 2026

Bug

Progress: NuGet/Home#14851

Description

Continues the NuGet.Protocol nullable annotation work. Removes #nullable disable from 8 more files and annotates public API surfaces.

Files migrated

  • HttpSourceCacheContext.csRootTempFolder made string?
  • NullSourceCacheContext.cs – fixed WithRefreshCacheTrue()/Clone() to use Instance property instead of _instance field (avoids returning null before first access)
  • PackageDownloadContext.csDirectDownloadDirectory, ClientPolicyContext, PackageSourceMapping made nullable; directDownloadDirectory and packageSourceMappingConfiguration parameters made nullable
  • RemoteSourceDependencyInfo.cscontentUri made non-null with ArgumentNullException guard (see risk note below); fixed Equals(object) which was incorrectly casting to PackageDependencyInfo instead of RemoteSourceDependencyInfo
  • SourceCacheContext.csClone() now assigns _generatedTempFolder via field instead of through the GeneratedTempFolder property (which has side effects); Dispose uses captured local
  • SourcePackageDependencyInfo.csSource, DownloadUri, PackageHash made nullable (all optional per XML docs)
  • UserAgent.cs – removed #nullable disable (no annotation changes needed)
  • UserAgentStringBuilder.cs_vsInfo, _osInfo, _ciInfo fields and WithVisualStudioSKU parameter made nullable

Risk note

RemoteSourceDependencyInfo constructor now throws ArgumentNullException for contentUri. Previously null was silently accepted. The ContentUri property is typed as non-null (string!) in the public API. Callers passing null today would hit a NullReferenceException later when the value is used — the new guard makes this fail-fast instead.

Bug fix

RemoteSourceDependencyInfo.Equals(object) was casting to PackageDependencyInfo instead of RemoteSourceDependencyInfo, meaning it always returned false for valid comparisons.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@dotnet-policy-service dotnet-policy-service Bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Apr 22, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant