{"record":{"id":"c712259587d3ad94","repo":"microsoft/aspire","slug":"all-resources-should-be-of-the-same-kind-when-calling","errorCode":null,"errorMessage":"All resources should be of the same kind when calling CreateRenderedResourcesAsync. Found resource kinds: {allResourceKinds}","messagePattern":"All resources should be of the same kind when calling CreateRenderedResourcesAsync\\. Found resource kinds: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/DcpExecutor.cs","lineNumber":955,"sourceCode":"    }\n\n    public async Task CreateRenderedResourcesAsync<TDcpResource, TContext>(\n       IObjectCreator<TDcpResource, TContext> creator,\n       IEnumerable<RenderedModelResource<TDcpResource>> resources,\n       TContext context,\n       CancellationToken cancellationToken)\n       where TDcpResource : CustomResource, IKubernetesStaticMetadata\n    {\n        if (!resources.Any())\n        {\n            return;\n        }\n        var allResources = resources.ToArray();\n\n        var allResourceKinds = allResources.Select(r => r.DcpResourceKind).Distinct();\n        if (allResourceKinds.Count() != 1)\n        {\n            throw new ArgumentException($\"All resources should be of the same kind when calling CreateRenderedResourcesAsync. Found resource kinds: {string.Join(\", \", allResourceKinds)}\");\n        }\n\n        var tasks = new List<Task>();\n\n        foreach (var group in allResources.GroupBy(e => e.ModelResource))\n        {\n            var groupList = group.ToList();\n            var groupKey = group.Key;\n            tasks.Add(Task.Run(() => CreateResourceReplicasAsync(groupKey, groupList, creator, context, cancellationToken), cancellationToken));\n        }\n        await Task.WhenAll(tasks).WaitAsync(cancellationToken).ConfigureAwait(false);\n    }\n\n    /// <summary>\n    /// Creates DCP resource replicas for a single Aspire model resource, handling all lifecycle events uniformly.\n    /// This is the unified creation path for all resource types (Executable, Container, ContainerExec).\n    /// </summary>\n    private async Task CreateResourceReplicasAsync<TDcpResource, TContext>(","sourceCodeStart":937,"sourceCodeEnd":973,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/DcpExecutor.cs#L937-L973","documentation":"CreateRenderedResourcesAsync requires every resource passed in to share a single DcpResourceKind; it throws ArgumentException listing all distinct kinds when they differ. The batch render/create path is designed for homogeneous resource groups.","triggerScenarios":"Calling CreateRenderedResourcesAsync with a collection whose resources resolve to more than one distinct DcpResourceKind (checked via Distinct().Count() != 1).","commonSituations":"Custom hosting code or an integration batching mixed resource types (e.g. Containers plus Executables) into one render call; refactoring bugs in custom DcpExecutor pipelines.","solutions":["Group resources by DcpResourceKind before calling CreateRenderedResourcesAsync and invoke it once per kind.","If you control the batching code, pass resources of one kind per call.","Verify no upstream code accidentally mixed resource collections (e.g. LINQ Select/Concat errors).","Update the integration package if the bug originates in a third-party integration."],"exampleFix":"// before\nawait executor.CreateRenderedResourcesAsync(mixedResources);\n// after\nforeach (var group in mixedResources.GroupBy(r => r.DcpResourceKind))\n{\n    await executor.CreateRenderedResourcesAsync(group.ToList());\n}","handlingStrategy":"validation","validationCode":"var kinds = resources.Select(r => r.DcpResourceKind).Distinct().ToList();\nif (kinds.Count != 1)\n    throw new InvalidOperationException($\"Batch must contain one resource kind, found: {string.Join(\", \", kinds)}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await executor.CreateRenderedResourcesAsync(resources);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"same kind\"))\n{\n    logger.LogError(ex, \"Mixed-kind batch passed to CreateRenderedResourcesAsync.\");\n}","preventionTips":["Group by DcpResourceKind before any batched create/render call.","Assert batch homogeneity in unit tests for custom executor pipelines.","Avoid Concat/Select refactors that silently merge different resource collections."],"tags":["dcp","argument-validation","batching"],"backgroundTag":"invalid-argument-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}