{"record":{"id":"0ea51323964ea33c","repo":"microsoft/aspire","slug":"failed-to-search-for-packages-exit-code-0","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/BundleNuGetPackageCache.cs","lineNumber":215,"sourceCode":"            environmentVariables: environmentVariables,\n            // A package search against a slow/unresponsive NuGet source can hang. LayoutProcessRunner uses\n            // this to bind the helper to the CLI's Windows kill-on-close job (and, on non-Windows, to\n            // instead arm the cooperative parent-liveness watchdog) so a hard-killed CLI cannot leak it.\n            killOnParentExit: true,\n            ct: cancellationToken).ConfigureAwait(false);\n\n        // Log stderr output (verbose info from NuGetHelper)\n        if (!string.IsNullOrWhiteSpace(error))\n        {\n            _logger.LogDebug(\"NuGetHelper stderr: {Error}\", error);\n        }\n\n        if (exitCode != 0)\n        {\n            _logger.LogError(\"NuGet search failed with exit code {ExitCode}\", exitCode);\n            _logger.LogError(\"NuGet search stderr: {Error}\", error);\n            _logger.LogError(\"NuGet search stdout: {Output}\", output);\n            throw new NuGetPackageCacheException(string.Format(CultureInfo.CurrentCulture, ErrorStrings.FailedToSearchForPackages, exitCode));\n        }\n\n        _logger.LogDebug(\"NuGet search returned {Length} bytes\", output?.Length ?? 0);\n\n        try\n        {\n            if (string.IsNullOrEmpty(output))\n            {\n                _logger.LogWarning(\"NuGet search returned empty output\");\n                return [];\n            }\n\n            // The aspire-managed helper writes the search result as JSON to stdout, but a NuGet credential\n            // provider can write diagnostics before or after that payload. Extract exactly one complete root object\n            // with the expected bundle-search shape so provider diagnostics cannot be deserialized as the result.\n            // See https://github.com/microsoft/aspire/issues/19339.\n            var result = JsonSerializer.Deserialize(PackageUpdateHelpers.ExtractJsonPayload(output, IsBundleSearchPayload), BundleSearchJsonContext.Default.BundleSearchResult);\n            if (result?.Packages is null)","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs#L197-L233","documentation":"After running aspire-managed nuget search, BundleNuGetPackageCache checks the process exit code. A non-zero exit code means the search command failed (e.g. network/feed errors), so it logs stderr/stdout and throws NuGetPackageCacheException with a message embedding the exit code.","triggerScenarios":"Any `packages` search or version query where the aspire-managed `nuget search` helper process exits non-zero — unreachable NuGet source, bad nuget.config, auth failure on a private feed, or invalid query arguments.","commonSituations":"Corporate proxy blocking nuget.org; private Azure DevOps feed requiring credentials with no configured credential provider; malformed nuget.config in the working directory or passed via --nuget-config; offline machine.","solutions":["Check CLI debug logs for the logged stderr/stdout of the failed search to see the underlying NuGet error","Verify network access to the NuGet source(s) and configure the proxy correctly","Fix or remove the nuget.config in the working directory (or pass a valid --nuget-config)","Ensure NuGet credential providers are installed for authenticated feeds and retry"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Validate feed reachability before search\ncurl -fsSL https://api.nuget.org/v3/index.json > /dev/null || echo \"NuGet source unreachable\"","typeGuard":null,"tryCatchPattern":"try\n{\n    await cache.SearchPackagesAsync(...);\n}\ncatch (NuGetPackageCacheException ex) when (ex.Message.StartsWith(\"Failed to search for packages\"))\n{\n    // inspect CLI debug logs for stderr; fix feed/proxy/credentials; retry\n}","preventionTips":["Configure proxy and corporate firewall rules for NuGet endpoints in advance","Install NuGet credential providers for any authenticated feeds","Validate nuget.config files in project directories before running package commands","Use --verbose/debug logging when debugging feed issues"],"tags":["nuget","network","search","feed"],"backgroundTag":"http-request-failed","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}