{"record":{"id":"b34572bc503e7421","repo":"microsoft/aspire","slug":"failed-to-search-for-packages-exit-code-0-nugetpackagecache","errorCode":null,"errorMessage":"Failed to search for packages. Exit code: {0}.","messagePattern":"Failed to search for packages\\. Exit code: (.+?)\\.","errorType":"exception","errorClass":"NuGetPackageCacheException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/NuGet/NuGetPackageCache.cs","lineNumber":144,"sourceCode":"        do\n        {\n            // This search should pick up Aspire.Hosting.* and CommunityToolkit.Aspire.Hosting.*\n            var result = await cliRunner.SearchPackagesAsync(\n                workingDirectory,\n                query,\n                exactMatch: false,\n                prerelease,\n                SearchPageSize,\n                skip,\n                nugetConfigFile,\n                useCache, // Pass through the useCache parameter\n                new ProcessInvocationOptions { SuppressLogging = true },\n                cancellationToken\n                );\n\n            if (result.ExitCode != 0)\n            {\n                throw new NuGetPackageCacheException(string.Format(CultureInfo.CurrentCulture, ErrorStrings.FailedToSearchForPackages, result.ExitCode));\n            }\n            else\n            {\n                if (result.Packages?.Length > 0)\n                {\n                    collectedPackages.AddRange(result.Packages);\n                }\n\n                if (result.Packages?.Length < SearchPageSize)\n                {\n                    continueFetching = false;\n                }\n                else\n                {\n                    continueFetching = true;\n                    skip += SearchPageSize;\n                }\n            }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/NuGet/NuGetPackageCache.cs#L126-L162","documentation":"NuGetPackageCache.GetPackagesAsync shells out to a NuGet search process (e.g. `dotnet package search`) and throws NuGetPackageCacheException when that process returns a non-zero exit code. The wrapped exit code identifies the underlying NuGet/dotnet CLI failure. This is how the Aspire CLI signals that package search could not complete.","triggerScenarios":"Calling GetPackagesAsync (directly or via the `packages`/`aspire add` search flow) when the spawned search process exits non-zero: bad feed, network failure, invalid NuGet.config, or dotnet CLI error.","commonSituations":"Offline or proxied networks blocking the search endpoint; a broken corporate NuGet.config feed; a `dotnet package search` command not supported by the installed SDK version.","solutions":["Run `dotnet nuget list source` and verify the feed is reachable; fix or remove broken sources.","Re-run the same search manually (dotnet package search) to see the real error and exit code.","Check network/proxy/VPN connectivity to nuget.org.","Update the .NET SDK so the search command is supported."],"exampleFix":"// before: relying on ambient NuGet config with broken feeds\nvar packages = await cache.GetPackagesAsync(\"aspire\", false, false, ct);\n// after: ensure a healthy source before searching\nvar psi = Process.Start(new ProcessStartInfo(\"dotnet\", \"nuget list source\"));\npsi.WaitForExit();\nif (psi.ExitCode != 0) { /* repair NuGet.config first */ }\nvar packages = await cache.GetPackagesAsync(\"aspire\", false, false, ct);","handlingStrategy":"try-catch","validationCode":"var psi = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(\"dotnet\", \"nuget list source\"));\npsi.WaitForExit();\nbool feedHealthy = psi.ExitCode == 0;","typeGuard":null,"tryCatchPattern":"try\n{\n    var packages = await cache.GetPackagesAsync(term, prerelease, exact, ct);\n}\ncatch (NuGetPackageCacheException ex)\n{\n    logger.LogError(ex, \"Package search failed; check NuGet sources and network.\");\n    // surface exit code to user\n}","preventionTips":["Keep NuGet.config sources minimal and reachable","Test `dotnet package search` manually before scripting against the cache","Handle offline/proxy environments explicitly"],"tags":["nuget","package-search","process-exit-code","cli"],"backgroundTag":"command-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}