microsoft/aspire · error · InvalidOperationException
Service resources do not produce any services
Error message
Service resources do not produce any services
What it means
In the DCP model, AppResource wrappers expose ServicesProduced/ServicesConsumed lists describing service-to-service relationships. A ServiceWithModelResource wraps a DCP Service object, which by definition does not produce services — the base class contract requires the property, so the getter throws InvalidOperationException to mark the operation as meaningless for this subtype.
Solutions
- Filter resources by concrete type (e.g. pattern-match on ContainerResource/ProjectResource) before accessing ServicesProduced
- Check whether the AppResource is a ServiceWithModelResource and skip it in service-graph traversal
- Read service relationships from the EndpointAnnotation on ServiceWithModelResource instead
Example fix
// before var produced = appResource.ServicesProduced; // throws for ServiceWithModelResource // after var produced = appResource is ServiceWithModelResource ? [] : appResource.ServicesProduced;
Defensive patterns
Strategy: type-guard
Validate before calling
if (appResource is ServiceWithModelResource)
{
// No ServicesProduced data; skip this resource.
return [];
} Type guard
bool HasProducedServices(AppResource r) => r is not ServiceWithModelResource;
Try / catch
try
{
var produced = appResource.ServicesProduced;
}
catch (InvalidOperationException) when (appResource is ServiceWithModelResource)
{
var produced = [];
} Prevention
- Pattern-match the concrete AppResource type before touching service lists
- Use EndpointAnnotation on ServiceWithModelResource for service relationships
- Exclude Service resources when building produced/consumed service graphs
- Add unit coverage for traversal code over all AppResource subtypes
When it happens
Trigger: Code iterating DCP app resources and reading ServicesProduced on a ServiceWithModelResource instance instead of filtering to container/project resource types first.
Common situations: Dashboard or executor code that generically walks all AppResource subtypes without checking the concrete type; new code assuming every AppResource carries service-production info.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Service resources do not consume any services
- JSON Patch operation
- A JSON Patch operation must contain string 'op' and 'path'…
- All resources should be of the same kind when calling…
- Application orchestrator dependency check returned an…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/9b33e64e9408080a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/Dcp/AppResource.cs:89
public IResource ModelResource { get; }
public RenderedModelResource(IResource modelResource, TDcpResource dcpResource) : base(dcpResource)
{
ModelResource = modelResource;
}
public virtual List<ServiceWithModelResource> ServicesProduced { get; } = [];
public virtual List<ServiceWithModelResource> ServicesConsumed { get; } = [];
}
internal sealed class ServiceWithModelResource : RenderedModelResource<Service>
{
public Service Service => DcpResource;
public EndpointAnnotation EndpointAnnotation { get; }
public override List<ServiceWithModelResource> ServicesProduced
{
get { throw new InvalidOperationException("Service resources do not produce any services"); }
}
public override List<ServiceWithModelResource> ServicesConsumed
{
get { throw new InvalidOperationException("Service resources do not consume any services"); }
}
public ServiceWithModelResource(IResource modelResource, Service service, EndpointAnnotation sba) : base(modelResource, service)
{
EndpointAnnotation = sba;
}
}
internal interface IResourceReference
{
IResource ModelResource { get; }
string DcpResourceName { get; }
}
View on GitHub (pinned to 25830f84bd)