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

  1. Reinstall/update the Aspire CLI so aspire-managed and the CLI schema versions match
  2. Disable or repair problematic NuGet credential providers that write to stdout
  3. Run the search again with debug logging (--verbose / debug logs) to inspect raw search output
  4. 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

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.

Related errors


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)