{"record":{"id":"9b9d14cfaeaedc07","repo":"microsoft/aspire","slug":"failed-to-retrieve-container-registry-information","errorCode":null,"errorMessage":"Failed to retrieve container registry information.","messagePattern":"Failed to retrieve container registry information\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ContainerRegistry/AzureContainerRegistryHelpers.cs","lineNumber":29,"sourceCode":"using Microsoft.Extensions.DependencyInjection;\n\nnamespace Aspire.Hosting.Azure;\n\n/// <summary>\n/// Helper methods for Azure Container Registry operations.\n/// </summary>\ninternal static class AzureContainerRegistryHelpers\n{\n    public static async Task LoginToRegistryAsync(IContainerRegistry registry, PipelineStepContext context)\n    {\n        var acrLoginService = context.Services.GetRequiredService<IAcrLoginService>();\n        var tokenCredentialProvider = context.Services.GetRequiredService<ITokenCredentialProvider>();\n\n        // Find the AzureEnvironmentResource from the application model\n        var azureEnvironment = context.Model.Resources.OfType<AzureEnvironmentResource>().FirstOrDefault() ??\n            throw new InvalidOperationException(\"AzureEnvironmentResource must be present in the application model.\");\n        var registryName = await registry.Name.GetValueAsync(context.CancellationToken).ConfigureAwait(false) ??\n            throw new InvalidOperationException(\"Failed to retrieve container registry information.\");\n\n        var registryEndpoint = await registry.Endpoint.GetValueAsync(context.CancellationToken).ConfigureAwait(false) ??\n            throw new InvalidOperationException(\"Failed to retrieve container registry endpoint.\");\n\n        var loginTask = await context.ReportingStep.CreateTaskAsync(\n            new MarkdownString($\"Logging in to **{registryName}**\"),\n            context.CancellationToken).ConfigureAwait(false);\n        await using (loginTask.ConfigureAwait(false))\n        {\n            try\n            {\n                // Get tenant ID from the provisioning context (always available from subscription)\n                var provisioningContext = await azureEnvironment.ProvisioningContextTask.Task.ConfigureAwait(false);\n                var tenantId = provisioningContext.Tenant.TenantId?.ToString()\n                    ?? throw new InvalidOperationException(\"Tenant ID is required for ACR authentication but was not available in provisioning context.\");\n\n                // Use the ACR login service to perform authentication\n                await acrLoginService.LoginAsync(","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ContainerRegistry/AzureContainerRegistryHelpers.cs#L11-L47","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure the registry name is set, e.g. via AddAzureContainerRegistry(\"name\") or by assigning the Name parameter from a valid value/reference.","If building the resource manually, set registry.Name to a concrete non-null value before login runs.","Check for app-model transformations or custom callbacks that clear or rename registry parameters.","Capture the underlying provisioning output and log it to confirm whether the name reference ever resolves."],"exampleFix":"// before\nvar registry = builder.AddAzureContainerRegistry(\"\"); // name not set\n// after\nvar registry = builder.AddAzureContainerRegistry(\"myregistry\");","handlingStrategy":"validation","validationCode":"var registryName = await registry.Name.GetValueAsync(ct);\nif (string.IsNullOrEmpty(registryName))\n{\n    throw new InvalidOperationException(\"Container registry Name is not set; pass a name to AddAzureContainerRegistry.\");\n}","typeGuard":"bool registryNameResolved = await registry.Name.GetValueAsync(ct) is string n && !string.IsNullOrEmpty(n);","tryCatchPattern":"try\n{\n    await LoginToRegistryAsync(registry, context);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"registry information\"))\n{\n    logger.LogError(\"Registry name reference resolved to null; check registry resource setup.\");\n    throw;\n}","preventionTips":["Always pass a non-empty name to AddAzureContainerRegistry.","Avoid custom app-model transformations that clear parameter references.","Log resolved registry parameters during publish to catch nulls early."],"tags":["azure","container-registry","null-value","app-model"],"backgroundTag":"missing-required-config-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}