{"record":{"id":"9b33e64e9408080a","repo":"microsoft/aspire","slug":"service-resources-do-not-produce-any-services","errorCode":null,"errorMessage":"Service resources do not produce any services","messagePattern":"Service resources do not produce any services","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/AppResource.cs","lineNumber":89,"sourceCode":"    public IResource ModelResource { get; }\n\n    public RenderedModelResource(IResource modelResource, TDcpResource dcpResource) : base(dcpResource)\n    {\n        ModelResource = modelResource;\n    }\n\n    public virtual List<ServiceWithModelResource> ServicesProduced { get; } = [];\n    public virtual List<ServiceWithModelResource> ServicesConsumed { get; } = [];\n}\n\ninternal sealed class ServiceWithModelResource : RenderedModelResource<Service>\n{\n    public Service Service => DcpResource;\n    public EndpointAnnotation EndpointAnnotation { get; }\n\n    public override List<ServiceWithModelResource> ServicesProduced\n    {\n        get { throw new InvalidOperationException(\"Service resources do not produce any services\"); }\n    }\n    public override List<ServiceWithModelResource> ServicesConsumed\n    {\n        get { throw new InvalidOperationException(\"Service resources do not consume any services\"); }\n    }\n\n    public ServiceWithModelResource(IResource modelResource, Service service, EndpointAnnotation sba) : base(modelResource, service)\n    {\n        EndpointAnnotation = sba;\n    }\n}\n\ninternal interface IResourceReference\n{\n    IResource ModelResource { get; }\n    string DcpResourceName { get; }\n}\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/AppResource.cs#L71-L107","documentation":"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.","triggerScenarios":"Code iterating DCP app resources and reading ServicesProduced on a ServiceWithModelResource instance instead of filtering to container/project resource types first.","commonSituations":"Dashboard or executor code that generically walks all AppResource subtypes without checking the concrete type; new code assuming every AppResource carries service-production info.","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"],"exampleFix":"// before\nvar produced = appResource.ServicesProduced; // throws for ServiceWithModelResource\n// after\nvar produced = appResource is ServiceWithModelResource ? [] : appResource.ServicesProduced;","handlingStrategy":"type-guard","validationCode":"if (appResource is ServiceWithModelResource)\n{\n    // No ServicesProduced data; skip this resource.\n    return [];\n}","typeGuard":"bool HasProducedServices(AppResource r) => r is not ServiceWithModelResource;","tryCatchPattern":"try\n{\n    var produced = appResource.ServicesProduced;\n}\ncatch (InvalidOperationException) when (appResource is ServiceWithModelResource)\n{\n    var produced = [];\n}","preventionTips":["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"],"tags":["dcp","services","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}