microsoft/aspire · error · InvalidOperationException

Failed to retrieve container registry information.

Error message

Failed to retrieve container registry information.

What it means

During registry login, the registry resource's Name reference is resolved asynchronously; if it evaluates to null the library cannot identify which registry to log into and throws InvalidOperationException. This is a guard against a broken or unassigned registry name parameter in the app model.

Solutions

  1. Ensure the registry name is set, e.g. via AddAzureContainerRegistry("name") or by assigning the Name parameter from a valid value/reference.
  2. If building the resource manually, set registry.Name to a concrete non-null value before login runs.
  3. Check for app-model transformations or custom callbacks that clear or rename registry parameters.
  4. Capture the underlying provisioning output and log it to confirm whether the name reference ever resolves.

Example fix

// before
var registry = builder.AddAzureContainerRegistry(""); // name not set
// after
var registry = builder.AddAzureContainerRegistry("myregistry");
Defensive patterns

Strategy: validation

Validate before calling

var registryName = await registry.Name.GetValueAsync(ct);
if (string.IsNullOrEmpty(registryName))
{
    throw new InvalidOperationException("Container registry Name is not set; pass a name to AddAzureContainerRegistry.");
}

Type guard

bool registryNameResolved = await registry.Name.GetValueAsync(ct) is string n && !string.IsNullOrEmpty(n);

Try / catch

try
{
    await LoginToRegistryAsync(registry, context);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("registry information"))
{
    logger.LogError("Registry name reference resolved to null; check registry resource setup.");
    throw;
}

Prevention

When it happens

Trigger: A AzureContainerRegistryResource whose Name reference parameter was never assigned a value, or whose value pipeline produced null when GetValueAsync is awaited (e.g. the registry resource was constructed without the required provisioning outputs).

Common situations: Programmatically constructing or transforming registry resources (custom publish steps, test harnesses) and forgetting to set the Name parameter; overriding provisioning so the name output is never populated.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.ContainerRegistry/AzureContainerRegistryHelpers.cs:29

using Microsoft.Extensions.DependencyInjection;

namespace Aspire.Hosting.Azure;

/// <summary>
/// Helper methods for Azure Container Registry operations.
/// </summary>
internal static class AzureContainerRegistryHelpers
{
    public static async Task LoginToRegistryAsync(IContainerRegistry registry, PipelineStepContext context)
    {
        var acrLoginService = context.Services.GetRequiredService<IAcrLoginService>();
        var tokenCredentialProvider = context.Services.GetRequiredService<ITokenCredentialProvider>();

        // Find the AzureEnvironmentResource from the application model
        var azureEnvironment = context.Model.Resources.OfType<AzureEnvironmentResource>().FirstOrDefault() ??
            throw new InvalidOperationException("AzureEnvironmentResource must be present in the application model.");
        var registryName = await registry.Name.GetValueAsync(context.CancellationToken).ConfigureAwait(false) ??
            throw new InvalidOperationException("Failed to retrieve container registry information.");

        var registryEndpoint = await registry.Endpoint.GetValueAsync(context.CancellationToken).ConfigureAwait(false) ??
            throw new InvalidOperationException("Failed to retrieve container registry endpoint.");

        var loginTask = await context.ReportingStep.CreateTaskAsync(
            new MarkdownString($"Logging in to **{registryName}**"),
            context.CancellationToken).ConfigureAwait(false);
        await using (loginTask.ConfigureAwait(false))
        {
            try
            {
                // Get tenant ID from the provisioning context (always available from subscription)
                var provisioningContext = await azureEnvironment.ProvisioningContextTask.Task.ConfigureAwait(false);
                var tenantId = provisioningContext.Tenant.TenantId?.ToString()
                    ?? throw new InvalidOperationException("Tenant ID is required for ACR authentication but was not available in provisioning context.");

                // Use the ACR login service to perform authentication
                await acrLoginService.LoginAsync(

View on GitHub (pinned to 25830f84bd)