{"record":{"id":"9a98c5d00ba2cd6e","repo":"microsoft/aspire","slug":"failed-to-parse-package-search-results","errorCode":null,"errorMessage":"Failed to parse package search results.","messagePattern":"Failed to parse package search results\\.","errorType":"exception","errorClass":"NuGetPackageCacheException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs","lineNumber":267,"sourceCode":"            {\n                var exactMatchResultPackage = result.Packages\n                    .FirstOrDefault(p => p.Id.Equals(query, StringComparison.Ordinal));\n                if (exactMatchResultPackage is null || exactMatchResultPackage.AllVersions is null)\n                {\n                    return [];\n                }\n                return exactMatchResultPackage.AllVersions.Select(packageVersion => new NuGetPackage\n                {\n                    Id = exactMatchResultPackage.Id,\n                    Version = packageVersion,\n                    Source = exactMatchResultPackage.Source ?? string.Empty\n                }).ToList();\n            }\n        }\n        catch (JsonException ex)\n        {\n            _logger.LogError(ex, \"Failed to parse search results\");\n            throw new NuGetPackageCacheException(ErrorStrings.FailedToParsePackageSearchResults);\n        }\n    }\n\n    private static bool IsBundleSearchPayload(JsonElement root)\n    {\n        return root.ValueKind == JsonValueKind.Object &&\n            root.TryGetProperty(\"packages\", out var packages) &&\n            packages.ValueKind == JsonValueKind.Array &&\n            root.TryGetProperty(\"totalHits\", out var totalHits) &&\n            totalHits.ValueKind == JsonValueKind.Number;\n    }\n\n    private IEnumerable<NuGetPackage> FilterPackages(IEnumerable<NuGetPackage> packages, Func<string, bool>? filter)\n    {\n        var showDeprecatedPackages = _features.IsFeatureEnabled(KnownFeatures.ShowDeprecatedPackages, defaultValue: false);\n        var effectiveFilter = (NuGetPackage p) =>\n        {\n            if (filter is not null)","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs#L249-L285","documentation":"The aspire-managed nuget search writes a JSON payload ({packages:[], totalHits:n}) to stdout, but credential providers or other tools may inject diagnostic text around it. BundleNuGetPackageCache extracts the payload and deserializes it; a JsonException during parsing is rethrown as NuGetPackageCacheException 'Failed to parse package search results.', meaning the output could not be interpreted as the expected bundle search shape.","triggerScenarios":"JsonException while deserializing the search output in SearchPackagesInternalAsync — e.g. aspire-managed emitted truncated or non-JSON output, or the payload extraction found no object matching the expected shape so deserialization hit malformed text.","commonSituations":"A NuGet credential provider writes diagnostics that corrupt stdout; mismatched CLI/aspire-managed versions producing an unexpected JSON schema; the helper crashed mid-write leaving truncated JSON.","solutions":["Reinstall/update the Aspire CLI so aspire-managed and the CLI schema versions match","Disable or repair problematic NuGet credential providers that write to stdout","Run the search again with debug logging (--verbose / debug logs) to inspect raw search output","Check CLI debug logs for the inner JsonException details to identify the malformed content"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Sanity-check expected payload shape before trusting parsed results\nif (string.IsNullOrWhiteSpace(rawOutput) || !rawOutput.TrimStart().StartsWith(\"{\"))\n{\n    // treat as failed/unparseable output, retry or log diagnostics\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var packages = await cache.SearchPackagesAsync(...);\n}\ncatch (NuGetPackageCacheException ex) when (ex.Message.Contains(\"Failed to parse package search results\"))\n{\n    // retry with debug logging; fix credential providers writing to stdout; update CLI\n}","preventionTips":["Keep CLI and aspire-managed versions in lockstep (install via official channels)","Avoid credential providers that emit diagnostics to stdout; move them to stderr","Retry transient parses; persistent failures usually indicate version/schema mismatch","Report reproducible parse failures with the raw debug output attached"],"tags":["nuget","json","parse","bundle"],"backgroundTag":"json-parse-error","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"}