Skip to content

Fix #310: skip non-HTTP NuGet sources instead of crashing#317

Merged
richlander merged 3 commits intomainfrom
fix/issue-310-non-http-source-crash
May 4, 2026
Merged

Fix #310: skip non-HTTP NuGet sources instead of crashing#317
richlander merged 3 commits intomainfrom
fix/issue-310-non-http-source-crash

Conversation

@richlander
Copy link
Copy Markdown
Owner

Fixes #310.

A local folder source from NuGet.Config (e.g. D:\some\local\packages) listed before a working HTTP feed caused System.NotSupportedException: net_http_unsupported_requesturi_scheme, file when resolving package versions or downloading nupkgs. PackageExtractor.GetPackageBaseAddressAsync built a service-index URL from source.Url and handed it to HttpClient, whose HttpRequestMessage ctor throws on file/relative URLs.

Fix

  • In GetPackageBaseAddressAsync, return null for any source whose URL is not an absolute http/https URI (and log it). The download / list-versions / latest-version paths all flow through this method after the nuget.org flat-container shortcut, so one guard fixes all three. Existing source loops already treat null as "try next source", so HTTP feeds listed after a folder source now resolve correctly.
  • Defense in depth: catch NotSupportedException in HttpRetryHelper.ExecuteWithRetryAsync so any future code path that accidentally passes an unsupported URL degrades to a skipped source rather than crashing.

Tests

New LocalFolderSourceTests covers:

  • Windows folder paths, POSIX paths, file:// URLs, and unparseable URLs do not crash GetLatestVersionAsync, GetVersionsAsync, or GetPackageDownloadUrlAsync.
  • A local folder source listed before nuget.org no longer prevents resolution (exact scenario from the issue).
  • Skipped non-HTTP sources are surfaced via the log callback.

All existing tests still pass: DotnetInspector.Services.Tests 155/155, dotnet-inspect.Tests 614/614 (31 unrelated skips for missing ilspycmd).

Out of scope

Adding real support for enumerating versions / downloading from local folder sources (issue's suggested option 3). The primary requirement was "don't crash".

richlander and others added 3 commits May 4, 2026 11:02
A local folder source from NuGet.Config (e.g. `D:\some\local\packages`)
listed before a working HTTP feed caused
`System.NotSupportedException: net_http_unsupported_requesturi_scheme, file`
when resolving package versions or downloading nupkgs:
PackageExtractor.GetPackageBaseAddressAsync built a service-index URL from
source.Url and handed it to HttpClient, whose HttpRequestMessage ctor
throws on file/relative URLs.

Fix: in GetPackageBaseAddressAsync, return null for any source whose URL
is not an absolute http/https URI (and log it). The existing source loops
already treat null as 'try next source', so nuget.org / private HTTP feeds
listed after a folder source now resolve correctly.

Defense in depth: catch NotSupportedException in
HttpRetryHelper.ExecuteWithRetryAsync so any future code path that
accidentally passes an unsupported URL degrades to a skipped source
rather than crashing the command.

Adds regression tests covering:
- Windows folder paths, POSIX paths, file:// URLs, and unparseable URLs
  do not crash GetLatestVersionAsync, GetVersionsAsync, or
  GetPackageDownloadUrlAsync.
- A local folder source listed before nuget.org no longer prevents
  resolution from succeeding (the exact scenario from the issue).
- Skipped non-HTTP sources are surfaced via the log callback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… SDK regression

Direct stdout-to-file redirection (`cmd > file.md`) truncates the AOT
binary's output to ~256 bytes on the .NET 11 preview 3 SDK
(11.0.100-preview.3.26207.106) currently used by GitHub-hosted runners.
Piping through `cat` keeps the output complete. Reproduced locally on
macOS arm64 with the released 0.7.6 binary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@richlander richlander merged commit f651074 into main May 4, 2026
10 checks passed
@richlander richlander deleted the fix/issue-310-non-http-source-crash branch May 4, 2026 20:11
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.

--latest-version / --versions can crash when a local folder source appears before a valid HTTP NuGet feed

1 participant