microsoft/aspire · error · InvalidOperationException

The Microsoft Foundry model catalog produced no model…

Error message

The Microsoft Foundry model catalog produced no model descriptors after filtering. Refusing to overwrite the generated model descriptors with an empty catalog.

What it means

GenModel.cs filters the fetched Foundry model list into descriptor models (via GetLocalDescriptorModels or GetDistinctHostedModels). If every model is filtered out, regenerating would overwrite the generated extension methods with an empty set, so the tool throws rather than clobbering the checked-in generated code. Unlike error 970, the raw catalog had models but none survived filtering.

Solutions

  1. Dump the intermediate model list and check which filter (local vs hosted) eliminates all entries; update the filter logic for changed catalog metadata.
  2. Run against the correct endpoint for the chosen mode (isFoundryLocal) — mismatched endpoints yield models that fail the other mode's filters.
  3. Compare the current API response schema to the ApiResponse model classes and update deserialization if Foundry renamed fields used by the filters.
  4. If the catalog legitimately no longer contains supported models, coordinate a deliberate removal of generated code instead of letting the tool fail.

Example fix

// diagnostic before throwing
classifier: var local = GetLocalDescriptorModels(models).ToList();
var hosted = GetDistinctHostedModels(models).ToList();
Console.WriteLine($"raw={models.Count} local={local.Count} hosted={hosted.Count}");
Defensive patterns

Strategy: validation

Validate before calling

var descriptorModels = isFoundryLocal
    ? GetLocalDescriptorModels(models).ToList()
    : GetDistinctHostedModels(models).ToList();
if (descriptorModels.Count == 0 && models.Count > 0)
{
    Console.WriteLine($"All {models.Count} catalog models were filtered out; inspect filter logic before regenerating.");
}

Try / catch

try
{
    await RunGenModelAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("produced no model descriptors after filtering"))
{
    // do not overwrite generated code; investigate filters/metadata drift
}

Prevention

When it happens

Trigger: Running GenModel when models.Count > 0 but descriptorModels.Count == 0 after applying GetLocalDescriptorModels (local catalog filters) or GetDistinctHostedModels (dedup/hosting filters).

Common situations: Foundry changed model metadata (e.g. lifecycle/name/ SKU fields) so filters no longer match; running with isFoundryLocal=true against an endpoint whose models don't match local-descriptor criteria; newly renamed models dropping out of the distinct-hosted grouping.

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


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

Appendix: source

Thrown at src/Aspire.Hosting.Foundry/tools/GenModel.cs:35

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")
    : Path.Combine("..", "FoundryModel.Generated.cs");

File.WriteAllText(filename, generatedCode);
Console.WriteLine($"Generated extension methods written to {Path.GetFileName(filename)}");

// Also serialize the strongly typed response for output with pretty printing
var options = new JsonSerializerOptions
{

View on GitHub (pinned to 25830f84bd)