Describe the bug
Deploying a Foundry hosted agent fails when the underlying project endpoint is configured with WithHttpEndpoint(targetPort: 9000) before calling AsHostedAgent(project).
The deployment pipeline rejects the generated hosted agent endpoint because it contains the TargetPort endpoint property:
19:47:37 (deploy-proj-dotnet-hosted-agent-ha) ✗ [ERR] Step 'deploy-proj-dotnet-hosted-agent-ha' failed.
19:47:37 (deploy-proj-dotnet-hosted-agent-ha) ✗ Step 'deploy-proj-dotnet-hosted-agent-ha' failed: The endpoint property 'TargetPort' is
not supported for Foundry hosted agent endpoints. Only 'Url' and 'Scheme' are supported.
19:47:37 (pipeline-execution) ✗ [ERR] Step 'deploy-proj-dotnet-hosted-agent-ha' failed: The endpoint property 'TargetPort' is not
supported for Foundry hosted agent endpoints. Only 'Url' and 'Scheme' are supported.
It looks like AsHostedAgent(...)/deployment export is carrying through the TargetPort metadata from the Aspire project endpoint, but Foundry hosted agent endpoints only accept Url and Scheme.
Repro
Minimal AppHost from the repro repository:
#:sdk Aspire.AppHost.Sdk@13.4.0
#:package Aspire.Hosting.Foundry@13.4.0-preview.1.26281.15
#:package Aspire.Hosting.Python@13.4.0
#:project ./DotNetHostedAgent/DotNetHostedAgent.csproj
using Aspire.Hosting.Foundry;
var builder = DistributedApplication.CreateBuilder(args);
var foundry = builder.AddFoundry("aifskiresort");
var project = foundry.AddProject("projvoiceskiresort");
var chat = project.AddModelDeployment("gpt41", FoundryModel.OpenAI.Gpt41)
.WithProperties(configure => configure.SkuCapacity = 10);
builder.AddProject<Projects.DotNetHostedAgent>("proj-dotnet-hosted-agent")
.WithHttpEndpoint(targetPort: 9000)
.WithReference(chat).WaitFor(chat)
.AsHostedAgent(project);
builder.Build().Run();
The hosted agent app itself binds to the Aspire-provided DEFAULT_AD_PORT environment variable:
string port = Environment.GetEnvironmentVariable("DEFAULT_AD_PORT") ?? "8088";
builder.WebHost.UseUrls($"http://+:{port}");
Steps:
- Create/use the AppHost above with a web project converted to a Foundry hosted agent via
.AsHostedAgent(project).
- Deploy the Aspire app.
- Observe the hosted agent deploy step fails with the
TargetPort unsupported error.
Expected behavior
Deployment should succeed, or the Foundry hosted agent deployment/export path should omit/translate endpoint properties that Foundry hosted agent endpoints do not support.
If targetPort is fundamentally unsupported for hosted agents, Aspire should ideally fail earlier during AppHost validation with an actionable error rather than failing during the deployment step.
Actual behavior
The deployment pipeline fails at the hosted agent deployment step because the endpoint includes TargetPort, even though the endpoint was configured using the normal Aspire .WithHttpEndpoint(targetPort: 9000) API.
Versions
- AppHost SDK:
Aspire.AppHost.Sdk@13.4.0
- Foundry hosting package:
Aspire.Hosting.Foundry@13.4.0-preview.1.26281.15
- AppHost style: C# file-based AppHost (
apphost.cs)
- Hosted project target framework:
net10.0
Describe the bug
Deploying a Foundry hosted agent fails when the underlying project endpoint is configured with
WithHttpEndpoint(targetPort: 9000)before callingAsHostedAgent(project).The deployment pipeline rejects the generated hosted agent endpoint because it contains the
TargetPortendpoint property:It looks like
AsHostedAgent(...)/deployment export is carrying through theTargetPortmetadata from the Aspire project endpoint, but Foundry hosted agent endpoints only acceptUrlandScheme.Repro
Minimal AppHost from the repro repository:
The hosted agent app itself binds to the Aspire-provided
DEFAULT_AD_PORTenvironment variable:Steps:
.AsHostedAgent(project).TargetPortunsupported error.Expected behavior
Deployment should succeed, or the Foundry hosted agent deployment/export path should omit/translate endpoint properties that Foundry hosted agent endpoints do not support.
If
targetPortis fundamentally unsupported for hosted agents, Aspire should ideally fail earlier during AppHost validation with an actionable error rather than failing during the deployment step.Actual behavior
The deployment pipeline fails at the hosted agent deployment step because the endpoint includes
TargetPort, even though the endpoint was configured using the normal Aspire.WithHttpEndpoint(targetPort: 9000)API.Versions
Aspire.AppHost.Sdk@13.4.0Aspire.Hosting.Foundry@13.4.0-preview.1.26281.15apphost.cs)net10.0