microsoft/aspire · error · InvalidDataException

The ' ' on resource ' ' should have an associated DCP…

Error message

The '{endpoint.Name}' on resource '{ts.ResourceName}' should have an associated DCP Service resource already set up

What it means

Every endpoint exposed from a model resource should have had a corresponding DCP Service created during earlier phases. When a container tunnel looks up that Service (by resource name + endpoint name) and finds none, the internal contract is broken, so this throw fires.

Solutions

  1. Restart the AppHost so all endpoint services are (re)created before tunnels are wired.
  2. Verify endpoint names on the tunneled resource match those used by tunnel configuration.
  3. Update Aspire packages; if reproducible, report as a bug since this path is documented as unreachable.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    app.Run();
}
catch (InvalidDataException ex) when (ex.Message.Contains("should have an associated DCP Service"))
{
    // restart to regenerate endpoint services; upgrade Aspire if reproducible
}

Prevention

When it happens

Trigger: AddContainerTunnelAllocatedEndpoints searches allAppResources for a ServiceWithModelResource matching ts.ResourceName and endpoint.Name; none exists because Service creation was skipped, renamed, or the tunnel annotation is stale.

Common situations: Endpoint name changes not propagated to tunnel wiring; partial startup where services for some endpoints were never created; Aspire internal bugs around tunnel/proxy service generation.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting/Dcp/DcpModelUtilities.cs:316

                if (!TryGetEndpoint(res, ts.EndpointName, out var endpoint))
                {
                    throw new InvalidDataException($"Service '{ts.Service!.Metadata.Name}' refers to endpoint '{ts.EndpointName}' that does not exist");
                }

                if (ts.Service?.HasCompleteAddress is not true)
                {
                    // This should never happen; if it does, we have a bug without a workaround for the user.
                    throw new InvalidDataException($"Container tunnel service {ts.Service?.Metadata.Name} should have valid address at this point");
                }

                var serverSvc = allAppResources.Get().OfType<ServiceWithModelResource>().FirstOrDefault(swr =>
                    string.Equals(swr.ModelResource.Name, ts.ResourceName, StringComparisons.ResourceName) &&
                    string.Equals(swr.EndpointAnnotation.Name, endpoint.Name, StringComparisons.EndpointAnnotationName)
                );
                if (serverSvc is null)
                {
                    // Should never happen -- we should have created a Service for every endpoint exposed from a resource.
                    throw new InvalidDataException($"The '{endpoint.Name}' on resource '{ts.ResourceName}' should have an associated DCP Service resource already set up");
                }

                var networkId = new NetworkIdentifier(ts.ContainerNetworkName!);
                var address = string.IsNullOrEmpty(ts.TunnelInstanceName) ? containerHostName : KnownHostNames.DefaultContainerTunnelHostName;
                var port = (int)ts.Service!.AllocatedPort!;

                var tunnelAllocatedEndpoint = new AllocatedEndpoint(
                    endpoint,
                    address,
                    port,
                    EndpointBindingMode.SingleAddress,
                    targetPortExpression: $$$"""{{- portForServing "{{{ts.Service.Metadata.Name}}}" -}}""",
                    networkId
                );
                endpoint.AllAllocatedEndpoints.AddOrUpdateAllocatedEndpoint(networkId, tunnelAllocatedEndpoint);
            }
        }
    }

View on GitHub (pinned to 25830f84bd)