microsoft/aspire · error · InvalidOperationException

Package restore failed

Error message

Package restore failed: {error}

What it means

RestorePackagesAsync runs `aspire-managed nuget restore` to restore the requested packages. A non-zero exit code indicates the restore itself failed; the method logs exit code, stderr and stdout, then throws InvalidOperationException 'Package restore failed: {error}' where {error} is the helper's stderr output.

Solutions

  1. Read the stderr content in the exception message and the CLI error logs to find the underlying NuGet error
  2. Verify the requested package id/version exist on the configured sources
  3. Fix feed credentials (refresh PAT / install credential provider) and proxy settings
  4. Retry; if the restore cache is corrupt, clear the package restore cache directory under the working directory
Defensive patterns

Strategy: retry

Validate before calling

// Pre-validate package ids/versions exist on the target feed
// e.g. check https://api.nuget.org/v3-flatcontainer/{id}/{version}/{id}.{version}.nupkg

Try / catch

try
{
    await service.RestorePackagesAsync(packages, workingDir);
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Package restore failed"))
{
    // read stderr in ex.Message; fix credentials/sources; retry
}

Prevention

When it happens

Trigger: `nuget restore` helper exits non-zero during RestorePackagesAsync — e.g. package id/version not found on configured sources, authenticated feed rejected credentials, network failure, or invalid target framework/runtime identifier combination.

Common situations: Private feed credentials missing/expired; package version pinned in the AppHost that no longer exists on the source; corporate proxy or offline environment; wrong --source or nuget.config supplied.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/634fc1d1263ec725. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Cli/NuGet/BundleNuGetService.cs:209

            environmentVariables: environmentVariables,
            // A restore against a slow/unresponsive NuGet source can hang. LayoutProcessRunner uses this
            // to bind the helper to the CLI's Windows kill-on-close job (and, on non-Windows, to instead
            // arm the cooperative parent-liveness watchdog) so a hard-killed CLI cannot leak it.
            killOnParentExit: true,
            ct: ct);

        // Log stderr at debug level for diagnostics
        if (!string.IsNullOrWhiteSpace(error))
        {
            _logger.LogDebug("NuGetHelper restore stderr: {Error}", error);
        }

        if (exitCode != 0)
        {
            _logger.LogError("Package restore failed with exit code {ExitCode}", exitCode);
            _logger.LogError("Package restore stderr: {Error}", error);
            _logger.LogError("Package restore stdout: {Output}", output);
            throw new InvalidOperationException($"Package restore failed: {error}");
        }

        // Step 2: Create package probe manifest
        // Prepend "nuget" subcommand for aspire-managed dispatch
        var manifestArgs = new List<string>
        {
            "nuget",
            "manifest",
            "--assets", assetsPath,
            "--output", manifestPath,
            "--framework", targetFramework
        };

        if (!string.IsNullOrEmpty(runtimeIdentifier))
        {
            manifestArgs.Add("--runtime-identifier");
            manifestArgs.Add(runtimeIdentifier);
        }

View on GitHub (pinned to 25830f84bd)