microsoft/aspire · error · InvalidOperationException
No container registry configured for Azure Cognitive…
Error message
No container registry configured for Azure Cognitive Services project resource '{aspireResource.Name}'. A container registry is required to publish hosted agents. What it means
When publishing (generating infrastructure for) hosted agents on a Foundry project, the project must know which container registry to pull agent images from. If neither an explicitly assigned registry nor a DefaultContainerRegistry is set, ConfigureInfrastructure throws this InvalidOperationException.
Solutions
- Call .WithAzureContainerRegistry(registryBuilder) on the Foundry project resource before publishing
- Ensure a DefaultContainerRegistry is set on the project resource (e.g. via a shared publish callback)
- Verify the publish path is taken only after registry configuration runs (ordering of builder calls)
Example fix
// before
var project = foundry.AddProject("agents");
// after
var project = foundry.AddProject("agents").WithAzureContainerRegistry(containerRegistry); Defensive patterns
Strategy: validation
Validate before calling
if (publishingHostedAgents && project.Resource.DefaultContainerRegistry is null)
{
project.WithAzureContainerRegistry(containerRegistry);
} Try / catch
try { /* publish / run in publish mode */ }
catch (InvalidOperationException ex) when (ex.Message.Contains("No container registry configured"))
{
// Configure an ACR and re-run publish.
} Prevention
- Always attach an Azure Container Registry to Foundry projects that publish hosted agents
- Verify publish-mode runs in CI so missing registry config fails early
- Set the registry in the same builder chain as the project resource
When it happens
Trigger: Running aspire publish / deploy-mode infrastructure generation for a Foundry project with hosted agents where no container registry was attached via WithAzureContainerRegistry (or equivalent) and no default registry exists on the resource.
Common situations: Running locally fine (no publish path) but failing on publish; forgetting to configure a registry in CI where the AppHost publishes hosted agents; a shared AppHost used across environments where only some set a registry.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- Azure Cognitive Services project resource
- Capability host ' ' on project ' ' requires a CosmosDB…
- Microsoft Foundry project resource
- Model must be a FoundryModel or a string model name.
- Model version and format are required when the model is…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/f6a5dba97c7e39f6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs:440
* Container registry for hosted agents
*
* Only provision registry dependencies when the project will publish a hosted agent
* or when the user has explicitly supplied a registry override.
*/
if (RequiresContainerRegistryProvisioning(aspireResource))
{
AzureProvisioningResource? registry = null;
if (aspireResource.TryGetLastAnnotation<ContainerRegistryReferenceAnnotation>(out var registryReferenceAnnotation) && registryReferenceAnnotation.Registry is AzureProvisioningResource r)
{
registry = r;
}
else if (aspireResource.DefaultContainerRegistry is not null)
{
registry = aspireResource.DefaultContainerRegistry;
}
else
{
throw new InvalidOperationException($"No container registry configured for Azure Cognitive Services project resource '{aspireResource.Name}'. A container registry is required to publish hosted agents.");
}
var containerRegistry = (ContainerRegistryService)registry.AddAsExistingResource(infra);
infra.Add(containerRegistry);
// Project needs this to pull hosted agent images during hosted-agent deployment.
var pullRa = containerRegistry.CreateRoleAssignment(ContainerRegistryBuiltInRole.AcrPull, RoleManagementPrincipalType.ServicePrincipal, projectPrincipalId);
// There's a bug in the CDK, see https://github.com/Azure/azure-sdk-for-net/issues/47265
pullRa.Name = BicepFunction.CreateGuid(containerRegistry.Id, project.Id, pullRa.RoleDefinitionId);
infra.Add(pullRa);
infra.Add(containerRegistry);
infra.Add(new ProvisioningOutput("AZURE_CONTAINER_REGISTRY_ENDPOINT", typeof(string))
{
Value = containerRegistry.LoginServer
});
infra.Add(new ProvisioningOutput("AZURE_CONTAINER_REGISTRY_NAME", typeof(string))
{
Value = containerRegistry.NameView on GitHub (pinned to 25830f84bd)