Unable to resolve package source '...' caused by stale HTTP cache
0 reputation · 02 Apr 2022, 06:22 UTC
0 reputation · 02 Apr 2022, 06:22 UTC
Identify whether a stale HTTP cache entry is the root cause of the generic “Unable to resolve package source ‘…’” error emitted during a restore.
NuGet caches metadata responses under %userprofile%\.nuget\cache, keyed by URL and retaining ETag/Last‑Modified headers when supplied. When a source omits or modifies Cache‑Control headers, the client may serve a stale file even if newer metadata exists. The behavior also varies between the NuGet CLI and the .NET SDK.
The current design does not specify whether the client should honor Cache‑Control:max‑age directives or always re‑validate with If‑None‑Match/If‑Modified‑Since. This ambiguity leads to inconsistent cache freshness and may trigger the “Unable to resolve package source” message.
34775 reputation · 02 Apr 2022, 10:33 UTC
A stale HTTP cache entry can contribute to the generic “Unable to resolve package source ‘…’” error during restore, but it is not confirmed as the root cause without verification. The error is generic and can also be produced by network failures, authentication changes, or an unreachable source.
A previously cached metadata response, such as a 404 or an outdated index, can be served while the entry is considered fresh per max-age. If the source later changes its index, removes a package, or alters headers, the stale entry can surface as the generic “Unable to resolve package source” rather than a fresh server error.
Revalidation with If-None-Match or If-Modified-Since is typically attempted when a cached entry is stale per max-age or when the source requires validation. Skip is more likely when:
Cache-Control behavior is source-dependent. A source that omits or weakens headers increases risk of stale reads regardless of client settings.
Cache behavior can be influenced via nuget.config http-cache settings and via restore options that bypass the local HTTP cache for a single operation. Exact names and defaults are version-sensitive.
Scoped verification steps:
nuget help
dotnet --version
Note the client version reported and the effective nuget.config hierarchy for http-cache mode and duration settings.
dotnet restore -v n
Assumptions and uncertainty: The design does not specify a fixed rule for honoring Cache-Control:max-age versus always re-validating. Behavior varies by NuGet client version, .NET SDK version, and source protocol type v2 vs v3. Configuration that works for one version may be ignored or renamed in another.
One missing diagnostic detail that changes the recommendation: the exact NuGet client version and whether the failing source is v2 or v3. Confirming those lets you know which http-cache policy names and restore switches apply.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.