microsoft/aspire · error · InvalidOperationException
The Microsoft Foundry model catalog returned the same…
Error message
The Microsoft Foundry model catalog returned the same continuation token twice. Refusing to overwrite the generated model descriptors with a partial catalog. Response: {GetResponseSnippet(pageResponse)} What it means
While paging the Foundry catalog, GetAllModelsAsync tracks the previous continuation token and throws if the service returns the identical token twice, which would loop forever and produce a partial catalog. The guard exists so generated descriptors are never overwritten from an incomplete page walk.
Solutions
- Retry the tool run after some time — repeated identical tokens from a degraded service are often transient.
- Inspect the response snippet to see the token values and confirm the server is not advancing pagination.
- Check whether a proxy/cache is serving stale pages; bypass caching or add no-cache headers in ModelClient.
- Verify the requested API version supports continuation tokens as the tool sends them; adjust paging parameters if the contract changed.
Defensive patterns
Strategy: retry
Try / catch
try
{
await RunGenModelAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("same continuation token twice"))
{
// service-side paging stall: back off and retry the whole run
} Prevention
- Bypass caches/proxies for catalog requests to avoid stale pages
- Retry the full pagination run with backoff on repeated tokens
- Monitor Foundry API version changes affecting continuation tokens
- Cap total pages walked as an additional loop guard
When it happens
Trigger: The Foundry catalog's next-page continuation token does not advance — consecutive pages return the same token — inside the do/while pagination loop of GetAllModelsAsync.
Common situations: Foundry service bug or degraded state where the next-page link is stale; cached/proxied responses replaying the same page; API version mismatch causing the server to ignore paging parameters; index larger than the server can page correctly.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- The Microsoft Foundry model catalog response did not…
- The Microsoft Foundry model catalog response included…
- Microsoft Foundry model catalog request failed with HTTP
- Microsoft Foundry projects are not supported when the…
- Model must be a FoundryModel or a string model name.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/23446f4f83a7b7a5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Foundry/tools/GenModel.cs:783
foreach (var model in pageModels)
{
allModels.Add(model);
}
Console.WriteLine($"Fetched page with {pageModels.Count} models. Total so far: {allModels.Count}");
// Check if there's a continuation token for the next page
previousToken = continuationToken;
continuationToken = apiResponse?.IndexEntitiesResponse?.ContinuationToken;
if (!string.IsNullOrEmpty(continuationToken))
{
Console.WriteLine($"Found continuation token for next page: {continuationToken.Substring(0, Math.Min(50, continuationToken.Length))}...");
// Check for infinite loop (same token repeated)
if (continuationToken == previousToken)
{
throw new InvalidOperationException($"The Microsoft Foundry model catalog returned the same continuation token twice. Refusing to overwrite the generated model descriptors with a partial catalog. Response: {GetResponseSnippet(pageResponse)}");
}
}
} while (!string.IsNullOrEmpty(continuationToken));
Console.WriteLine($"\n=== Pagination Complete ===");
Console.WriteLine($"Total pages fetched: {pageCount}");
Console.WriteLine($"Total models collected: {allModels.Count}");
RunFixups(allModels);
// Return the consolidated response using our model
return new ConsolidatedResponse
{
TotalCount = allModels.Count,
PagesCombined = "All pages fetched",
Entities = allModels
};View on GitHub (pinned to 25830f84bd)