microsoft/aspire · error · InvalidOperationException
Bundle layout not found. Cannot perform NuGet search in…
Error message
Bundle layout not found. Cannot perform NuGet search in bundle mode.
What it means
In bundle mode the Aspire CLI runs NuGet operations via an extracted self-contained bundle layout. SearchPackagesInternalAsync calls IBundleService.EnsureExtractedAndAcquireLayoutAsync and expects a layout lease; when the extracted layout is null (extraction failed or was not performed), it throws this InvalidOperationException because NuGet search cannot proceed without the bundle.
Solutions
- Reinstall the Aspire CLI bundle so it can extract a valid layout
- Check disk space and write permissions for the bundle extraction directory
- Run the CLI once interactively to force extraction, then retry the package search
- Update to the latest CLI version; report if bundle extraction consistently fails
Defensive patterns
Strategy: fallback
Validate before calling
// Precheck bundle availability before NuGet operations
var lease = await bundleService.EnsureExtractedAndAcquireLayoutAsync("cli", "precheck", ct);
if (lease?.Layout is null)
{
// reinstall or fall back to non-bundle path
} Try / catch
try
{
await cache.SearchPackagesAsync(...);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Bundle layout not found"))
{
// repair install / re-extract bundle, then retry once
} Prevention
- Reinstall the CLI cleanly when upgrading rather than copying binaries
- Ensure the bundle extraction directory has free disk space and write permission
- Avoid external cleanup jobs deleting the CLI's extraction cache while the CLI runs
- Run the CLI once after install to complete first-run extraction before scripting
When it happens
Trigger: Calling packages search / package-version listing through BundleNuGetPackageCache when EnsureExtractedAndAcquireLayoutAsync("cli", "nuget-search") returns a lease whose Layout is null.
Common situations: Corrupted or partial CLI bundle installation; the bundle extraction directory was deleted or cleaned while the CLI runs; running a bundle-mode binary in an environment where extraction is disallowed (read-only disk, permissions); bundle service misconfigured so discovery yields no layout.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- aspire-managed not found in layout.
- Bundle layout not found. Cannot perform NuGet restore in…
- Manifest creation failed
- aspire-managed not found in layout.
- aspire-managed not found in layout.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/4dc018cb82c1a06a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs:144
bool FilterExactIdMatch(string? id) => string.Equals(id, exactPackageId, StringComparison.Ordinal);
return FilterPackages(packages, FilterExactIdMatch);
}
private async Task<IEnumerable<NuGetPackage>> SearchPackagesInternalAsync(
DirectoryInfo workingDirectory,
string query,
bool exactMatch,
bool prerelease,
FileInfo? nugetConfigFile,
CancellationToken cancellationToken)
{
// Ensure the bundle is extracted and lease the version before launching aspire-managed.
using var layoutLease = await _bundleService.EnsureExtractedAndAcquireLayoutAsync("cli", "nuget-search", cancellationToken).ConfigureAwait(false);
var layout = layoutLease?.Layout;
if (layout is null)
{
throw new InvalidOperationException("Bundle layout not found. Cannot perform NuGet search in bundle mode.");
}
var managedPath = layout.GetManagedPath();
if (managedPath is null || !File.Exists(managedPath))
{
throw new InvalidOperationException("aspire-managed not found in layout.");
}
// Build arguments for NuGet search command (via aspire-managed nuget subcommand)
var args = new List<string>
{
"nuget",
"search",
"--query", query,
"--take", "1000",
"--format", "json"
};
View on GitHub (pinned to 25830f84bd)