microsoft/aspire · error · InvalidOperationException
The Microsoft Foundry model catalog returned no models…
Error message
The Microsoft Foundry model catalog returned no models. Refusing to overwrite the generated model descriptors with an empty catalog.
What it means
GenModel.cs is a source-generator tool that fetches the Microsoft Foundry model catalog and regenerates model descriptor extension methods. It throws this InvalidOperationException when the catalog API call succeeded but returned zero entities, because regenerating the checked-in generated files from an empty catalog would silently delete all model APIs. It is a deliberate safety guard against persisting an empty/incorrect catalog snapshot.
Solutions
- Re-run the tool after confirming the Foundry catalog endpoint is healthy; the empty response is often transient.
- Inspect the raw HTTP response (add logging in ModelClient.GetAllModelsAsync) to confirm whether the API truly returned zero entities or the deserialization dropped them.
- Verify the isFoundryLocal flag and endpoint URL: a wrong endpoint can serve an empty catalog.
- If the catalog genuinely has no models, do not regenerate — keep the existing generated descriptors and investigate the service side.
Defensive patterns
Strategy: retry
Validate before calling
// Before regenerating, sanity-check the fetched catalog
var models = allModelsResponse.Entities ?? [];
if (models.Count == 0)
{
Console.WriteLine("Foundry catalog returned no models; skipping regeneration.");
return;
} Try / catch
try
{
await RunGenModelAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("returned no models"))
{
// transient/empty catalog: log and retry later, keep existing generated files
} Prevention
- Run codegen only when the Foundry endpoint is known healthy
- Verify the isFoundryLocal flag matches the target endpoint
- Keep existing generated files in version control so failures are visible
- Check Foundry service status before scheduled regeneration runs
When it happens
Trigger: Running the GenModel tool when ModelClient.GetAllModelsAsync() returns a response whose Entities collection is empty (models.Count == 0) — e.g. the Foundry catalog API returned a valid envelope with no model entries.
Common situations: Foundry service outage or API behavior change returning empty entity lists; querying with wrong flags (isFoundryLocal pointing at an empty local catalog); transient backend state where the catalog index is temporarily empty; network proxies stripping response payloads.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- The Microsoft Foundry model catalog produced no model…
- -32602
- argument ' ' passed to capability ' ' contains a circular…
- aspire: build returned unexpected type %T
- aspire: returned unexpected type %T
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/dd30e359b6ea57e7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Foundry/tools/GenModel.cs:27
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Markdig;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
var isFoundryLocal = args.Contains("--local");
using var mc = new ModelClient(isFoundryLocal);
var allModelsResponse = await mc.GetAllModelsAsync().ConfigureAwait(false);
var models = allModelsResponse.Entities ?? [];
if (models.Count == 0)
{
throw new InvalidOperationException("The Microsoft Foundry model catalog returned no models. Refusing to overwrite the generated model descriptors with an empty catalog.");
}
var descriptorModels = isFoundryLocal
? GetLocalDescriptorModels(models)
: GetDistinctHostedModels(models).ToList();
if (descriptorModels.Count == 0)
{
throw new InvalidOperationException("The Microsoft Foundry model catalog produced no model descriptors after filtering. Refusing to overwrite the generated model descriptors with an empty catalog.");
}
// Generate C# extension methods for the models
var generatedCode = isFoundryLocal
? GenerateLocalCode("Aspire.Hosting.Foundry", descriptorModels)
: GenerateHostedCode("Aspire.Hosting.Foundry", descriptorModels);
// Write the generated code to a file
var filename = isFoundryLocal
? Path.Combine("..", "FoundryModel.Local.Generated.cs")View on GitHub (pinned to 25830f84bd)