microsoft/aspire · error · InvalidDataException

Host endpoint ' ' on resource ' ' should have an associated…

Error message

Host endpoint '{endpoint.Name}' on resource '{re.Resource.Name}' should have an associated DCP Service resource already set up

What it means

Before wiring host-resource endpoints into container networks, Aspire expects a matching DCP Service resource (per resource name + endpoint name) to have been created earlier. When none is found, an InvalidDataException is thrown - the endpoint/Service pre-setup step was skipped or ran out of order.

Solutions

  1. Ensure the DCP Service creation step runs before container network setup for the resource
  2. Verify endpoint names match exactly (case-sensitive) between the resource and its Service
  3. Recreate/refresh the app model so Services are regenerated for all endpoints
Defensive patterns

Strategy: validation

Validate before calling

var svc = appResources.OfType<ServiceWithModelResource>().FirstOrDefault(s => StringComparers.ResourceName.Equals(s.ModelResource.Name, name) && StringComparers.EndpointAnnotationName.Equals(s.EndpointAnnotation.Name, endpointName)); if (svc is null) { /* run service setup first */ }

Try / catch

try { await networkSetup(re); } catch (InvalidDataException ex) when (ex.Message.Contains("DCP Service resource")) { logger.LogError(ex, "Service for endpoint {Endpoint} missing; run service generation first", endpointName); }

Prevention

When it happens

Trigger: CreateContainerNetworkServicesForHostResource processes a HostResourceWithEndpoints whose endpoint name has no ServiceWithModelResource with the same model resource name and endpoint annotation name in _appResources.

Common situations: Custom pipelines or eventing that create host resources without running the Service setup step, endpoint renamed/added after services were generated, or interacting with container-network features out of order in custom code.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting/Dcp/ContainerCreator.cs:447

            }

            if (useTunnel && endpoint.Protocol != ProtocolType.Tcp)
            {
                resourceLogger.LogWarning("Host endpoint '{EndpointName}' on resource '{HostResource}' is referenced by a container resource, but the endpoint is using a network protocol '{Protocol}' other than TCP. Only TCP is supported for container-to-host references.", endpoint.Name, re.Resource.Name, endpoint.Protocol);
                continue;
            }

            var svc = Service.Create(serviceName);
            svc.Spec.AddressAllocationMode = AddressAllocationModes.Proxyless;
            svc.Spec.Protocol = PortProtocol.FromProtocolType(endpoint.Protocol);

            var serverSvc = _appResources.Get().OfType<ServiceWithModelResource>().FirstOrDefault(swr =>
                StringComparers.ResourceName.Equals(swr.ModelResource.Name, re.Resource.Name) &&
                StringComparers.EndpointAnnotationName.Equals(swr.EndpointAnnotation.Name, endpoint.Name)
            );
            if (serverSvc is null)
            {
                throw new InvalidDataException($"Host endpoint '{endpoint.Name}' on resource '{re.Resource.Name}' should have an associated DCP Service resource already set up");
            }

            TunnelConfiguration? tunnelConfig = null;
            if (useTunnel)
            {
                tunnelConfig = new TunnelConfiguration
                {
                    Name = serviceName,
                    ServerServiceName = serverSvc.DcpResource.Metadata.Name,
                    ServerServiceNamespace = string.Empty,
                    ClientServiceName = svc.Metadata.Name,
                    ClientServiceNamespace = string.Empty
                };
            }

            svc.Annotate(CustomResource.ResourceNameAnnotation, re.Resource.Name);
            svc.Annotate(CustomResource.EndpointNameAnnotation, endpoint.Name);
            svc.Annotate(CustomResource.ContainerNetworkAnnotation, KnownNetworkIdentifiers.DefaultAspireContainerNetwork.Value);

View on GitHub (pinned to 25830f84bd)