microsoft/aspire · error · NuGetPackageCacheException
Failed to parse package search results.
Error message
Failed to parse package search results.
What it means
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.
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
Defensive patterns
Strategy: retry
Validate before calling
// Sanity-check expected payload shape before trusting parsed results
if (string.IsNullOrWhiteSpace(rawOutput) || !rawOutput.TrimStart().StartsWith("{"))
{
// treat as failed/unparseable output, retry or log diagnostics
} Try / catch
try
{
var packages = await cache.SearchPackagesAsync(...);
}
catch (NuGetPackageCacheException ex) when (ex.Message.Contains("Failed to parse package search results"))
{
// retry with debug logging; fix credential providers writing to stdout; update CLI
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse project.assets.json
- aspire-managed not found in layout.
- aspire-managed not found in layout.
- Bundle layout not found. Cannot perform NuGet restore in…
- Bundle layout not found. Cannot perform NuGet search in…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/9a98c5d00ba2cd6e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs:267
{
var exactMatchResultPackage = result.Packages
.FirstOrDefault(p => p.Id.Equals(query, StringComparison.Ordinal));
if (exactMatchResultPackage is null || exactMatchResultPackage.AllVersions is null)
{
return [];
}
return exactMatchResultPackage.AllVersions.Select(packageVersion => new NuGetPackage
{
Id = exactMatchResultPackage.Id,
Version = packageVersion,
Source = exactMatchResultPackage.Source ?? string.Empty
}).ToList();
}
}
catch (JsonException ex)
{
_logger.LogError(ex, "Failed to parse search results");
throw new NuGetPackageCacheException(ErrorStrings.FailedToParsePackageSearchResults);
}
}
private static bool IsBundleSearchPayload(JsonElement root)
{
return root.ValueKind == JsonValueKind.Object &&
root.TryGetProperty("packages", out var packages) &&
packages.ValueKind == JsonValueKind.Array &&
root.TryGetProperty("totalHits", out var totalHits) &&
totalHits.ValueKind == JsonValueKind.Number;
}
private IEnumerable<NuGetPackage> FilterPackages(IEnumerable<NuGetPackage> packages, Func<string, bool>? filter)
{
var showDeprecatedPackages = _features.IsFeatureEnabled(KnownFeatures.ShowDeprecatedPackages, defaultValue: false);
var effectiveFilter = (NuGetPackage p) =>
{
if (filter is not null)View on GitHub (pinned to 25830f84bd)