microsoft/aspire · error · ArgumentException

All resources should be of the same kind when calling…

Error message

All resources should be of the same kind when calling CreateRenderedResourcesAsync. Found resource kinds: {allResourceKinds}

What it means

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.

Solutions

  1. Group resources by DcpResourceKind before calling CreateRenderedResourcesAsync and invoke it once per kind.
  2. If you control the batching code, pass resources of one kind per call.
  3. Verify no upstream code accidentally mixed resource collections (e.g. LINQ Select/Concat errors).
  4. Update the integration package if the bug originates in a third-party integration.

Example fix

// before
await executor.CreateRenderedResourcesAsync(mixedResources);
// after
foreach (var group in mixedResources.GroupBy(r => r.DcpResourceKind))
{
    await executor.CreateRenderedResourcesAsync(group.ToList());
}
Defensive patterns

Strategy: validation

Validate before calling

var kinds = resources.Select(r => r.DcpResourceKind).Distinct().ToList();
if (kinds.Count != 1)
    throw new InvalidOperationException($"Batch must contain one resource kind, found: {string.Join(", ", kinds)}");

Try / catch

try
{
    await executor.CreateRenderedResourcesAsync(resources);
}
catch (ArgumentException ex) when (ex.Message.Contains("same kind"))
{
    logger.LogError(ex, "Mixed-kind batch passed to CreateRenderedResourcesAsync.");
}

Prevention

When it happens

Trigger: Calling CreateRenderedResourcesAsync with a collection whose resources resolve to more than one distinct DcpResourceKind (checked via Distinct().Count() != 1).

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting/Dcp/DcpExecutor.cs:955

    }

    public async Task CreateRenderedResourcesAsync<TDcpResource, TContext>(
       IObjectCreator<TDcpResource, TContext> creator,
       IEnumerable<RenderedModelResource<TDcpResource>> resources,
       TContext context,
       CancellationToken cancellationToken)
       where TDcpResource : CustomResource, IKubernetesStaticMetadata
    {
        if (!resources.Any())
        {
            return;
        }
        var allResources = resources.ToArray();

        var allResourceKinds = allResources.Select(r => r.DcpResourceKind).Distinct();
        if (allResourceKinds.Count() != 1)
        {
            throw new ArgumentException($"All resources should be of the same kind when calling CreateRenderedResourcesAsync. Found resource kinds: {string.Join(", ", allResourceKinds)}");
        }

        var tasks = new List<Task>();

        foreach (var group in allResources.GroupBy(e => e.ModelResource))
        {
            var groupList = group.ToList();
            var groupKey = group.Key;
            tasks.Add(Task.Run(() => CreateResourceReplicasAsync(groupKey, groupList, creator, context, cancellationToken), cancellationToken));
        }
        await Task.WhenAll(tasks).WaitAsync(cancellationToken).ConfigureAwait(false);
    }

    /// <summary>
    /// Creates DCP resource replicas for a single Aspire model resource, handling all lifecycle events uniformly.
    /// This is the unified creation path for all resource types (Executable, Container, ContainerExec).
    /// </summary>
    private async Task CreateResourceReplicasAsync<TDcpResource, TContext>(

View on GitHub (pinned to 25830f84bd)