{"record":{"id":"fc8ef332c413ee97","repo":"microsoft/aspire","slug":"endpoint-endpoint-name-is-internal-foundry-hosted-agents-can","errorCode":null,"errorMessage":"Endpoint '{endpoint.Name}' is internal. Foundry hosted agents can only reference externally exposed endpoints during publish.","messagePattern":"Endpoint '(.+?)' is internal\\. Foundry hosted agents can only reference externally exposed endpoints during publish\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/HostedAgent/AzureHostedAgentResource.cs","lineNumber":469,"sourceCode":"        }\n\n        return string.Format(CultureInfo.InvariantCulture, expression.Format, args);\n    }\n\n    private static async ValueTask<string?> ResolvePublishedEndpointAsync(\n        EndpointReferenceExpression endpointReferenceExpression,\n        DistributedApplicationExecutionContext context,\n        AzureHostedAgentResource hostedAgent,\n        IResource resource,\n        string environmentVariableName,\n        CancellationToken cancellationToken)\n    {\n        var endpointReference = endpointReferenceExpression.Endpoint;\n        var endpoint = endpointReference.EndpointAnnotation;\n\n        if (endpointReference.Resource != hostedAgent.Target && !endpoint.IsExternal)\n        {\n            throw CreateEndpointResolutionException(hostedAgent, resource, environmentVariableName, endpointReference, $\"Endpoint '{endpoint.Name}' is internal. Foundry hosted agents can only reference externally exposed endpoints during publish.\");\n        }\n\n        if (!ComputeEnvironmentEndpointResolver.TryGetEffectiveComputeEnvironment(endpointReference.Resource, out var computeEnvironment))\n        {\n            var reason = $\"Resource '{endpointReference.Resource.Name}' does not have a compute environment deployment target.\";\n            throw CreateEndpointResolutionException(hostedAgent, resource, environmentVariableName, endpointReference, reason);\n        }\n\n#pragma warning disable ASPIRECOMPUTE002\n        var expression = computeEnvironment.GetEndpointPropertyExpression(endpointReferenceExpression);\n#pragma warning restore ASPIRECOMPUTE002\n\n        return await expression.GetValueAsync(\n            new ValueProviderContext\n            {\n                ExecutionContext = context,\n                Caller = resource\n            },","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/HostedAgent/AzureHostedAgentResource.cs#L451-L487","documentation":"During publish, Aspire resolves environment variables for Azure Foundry hosted agents from endpoint references. Only externally exposed endpoints (or endpoints on the agent's own target resource) may be referenced, because publish bakes concrete URLs into the deployed agent's configuration. ResolvePublishedEndpointAsync throws this when an endpoint reference points at an internal (non-external) endpoint.","triggerScenarios":"A hosted agent's environment variable is bound via an endpoint reference whose EndpointAnnotation has IsExternal == false and whose resource is not hostedAgent.Target, while running in publish/deploy mode (ResolveValueProviderAsync path).","commonSituations":"Binding to an internal-only service endpoint and publishing; the referenced project lacks .WithExternalHttpEndpoints(); copy-pasted run-mode binding code applied to a published agent.","solutions":["Mark the referenced endpoint external on the owning resource (e.g. .WithExternalHttpEndpoints()).","Reference the hosted agent's own target resource endpoints directly if internal access is intended.","Bind to the resource's connection string or a different externally-exposed endpoint.","If the endpoint must stay internal, use a service-discovery reference rather than a baked endpoint value in the agent environment."],"exampleFix":"// before\nbuilder.AddProject<Projects.Agent>(\"agent\")\n    .WithEnvironment(\"API_URL\", api.GetEndpoint(\"http\")); // internal endpoint\n\n// after\nvar api = builder.AddProject<Projects.Api>(\"api\")\n    .WithExternalHttpEndpoints();\nbuilder.AddProject<Projects.Agent>(\"agent\")\n    .WithEnvironment(\"API_URL\", api.GetEndpoint(\"https\"));","handlingStrategy":"validation","validationCode":"// Detect internal endpoint references on a hosted agent before publish\nforeach (var env in agent.EnvironmentVariables)\n{\n    if (env.Value is EndpointReference ep &&\n        ep.Resource != agent.Target && !ep.EndpointAnnotation.IsExternal)\n    {\n        throw new InvalidOperationException(\n            $\"{env.Name} references internal endpoint '{ep.EndpointAnnotation.Name}'. Mark it external before publish.\");\n}","typeGuard":"static bool IsPublishableEndpoint(EndpointReference ep, IResource agentTarget) =>\n    ep.Resource == agentTarget || ep.EndpointAnnotation.IsExternal;","tryCatchPattern":null,"preventionTips":["Call .WithExternalHttpEndpoints() on any project whose endpoints a hosted agent references.","Keep run-mode and publish-mode bindings separate; don't reuse internal endpoint bindings in publish.","Review agent environment bindings before running aspire publish/deploy."],"tags":["azure","foundry","publish","endpoint","configuration"],"backgroundTag":"invalid-argument-value","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"}