{"record":{"id":"078421bd13027ab5","repo":"microsoft/aspire","slug":"expected-an-containerexec-resource-but-got-er","errorCode":null,"errorMessage":"Expected an ContainerExec resource, but got {er.DcpResourceKind} instead","messagePattern":"Expected an ContainerExec resource, but got (.+?) instead","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Dcp/ContainerCreator.cs","lineNumber":410,"sourceCode":"\n        await factory.CreateDcpObjectsAsync(new[] { dcpContainer }, cToken).ConfigureAwait(false);\n\n        var containerExes = _appResources.Get().OfType<RenderedModelResource<ContainerExec>>().Where(ar => ar.DcpResource.Spec.ContainerName == dcpContainer.Metadata.Name).ToArray();\n        if (containerExes.Length > 0)\n        {\n            IObjectCreator<ContainerExec, EmptyCreationContext> containerExecCreator = this;\n            await factory.CreateRenderedResourcesAsync(containerExecCreator, containerExes, EmptyCreationContext.s_instance, cToken).ConfigureAwait(false);\n        }\n    }\n\n    bool IObjectCreator<ContainerExec, EmptyCreationContext>.IsReadyToCreate(RenderedModelResource<ContainerExec> resource, EmptyCreationContext context)\n        => true;\n\n    async Task IObjectCreator<ContainerExec, EmptyCreationContext>.CreateObjectAsync(RenderedModelResource<ContainerExec> er, EmptyCreationContext context, ILogger _, IDcpObjectFactory factory, CancellationToken cancellationToken)\n    {\n        if (er.DcpResource is not ContainerExec containerExe)\n        {\n            throw new InvalidOperationException($\"Expected an {nameof(ContainerExec)} resource, but got {er.DcpResourceKind} instead\");\n        }\n\n        await factory.CreateDcpObjectsAsync([containerExe], cancellationToken).ConfigureAwait(false);\n    }\n\n    internal IEnumerable<ContainerNetworkService> CreateContainerNetworkServicesForHostResource(HostResourceWithEndpoints re)\n    {\n        var resourceLogger = _loggerService.GetLogger(re.Resource);\n        var services = new List<ContainerNetworkService>();\n        var useTunnel = _options.Value.EnableAspireContainerTunnel;\n        string tunnelProxyName = useTunnel ? GetTunnelProxyResourceName() : \"\";\n\n        foreach (var endpoint in re.Endpoints)\n        {\n            var (serviceName, isNew) = _nameGenerator.GetServiceName(re.Resource, endpoint, KnownNetworkIdentifiers.DefaultAspireContainerNetwork);\n            if (!isNew)\n            {\n                continue;","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Dcp/ContainerCreator.cs#L392-L428","documentation":"This creator only knows how to turn DCP ContainerExec resources into created objects. If the rendered model resource's DcpResource is some other kind, an InvalidOperationException is thrown - an internal invariant violation indicating the resource was routed to the wrong creator.","triggerScenarios":"A ContainerExec-typed model resource is dispatched to this creator while its underlying DCP object is a different kind (mismatch between DcpResourceKind and expected ContainerExec).","commonSituations":"Almost always an Aspire/DCP internal bug or version mismatch between the model builder and DCP object factory rather than user error.","solutions":["Check the resource definition to confirm the expected DCP resource kind","Upgrade Aspire.Hosting / DCP to matching versions","Report as a bug if it reproduces with a standard ContainerExec resource"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"if (rendered.DcpResource is not ContainerExec exec) throw new InvalidOperationException($\"Expected ContainerExec but got {rendered.DcpResourceKind}\");","tryCatchPattern":"try { await creator.CreateObjectAsync(er, ctx, logger, factory, ct); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"ContainerExec\")) { logger.LogError(ex, \"Wrong creator for DCP resource kind {Kind}\", er.DcpResourceKind); }","preventionTips":["Match object creators to DcpResourceKind in your dispatch table","Keep Aspire.Hosting and DCP versions aligned","Add a dispatch test that routes each kind to its expected creator"],"tags":["containers","internal-error","type-mismatch"],"backgroundTag":"type-mismatch","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"}