{"record":{"id":"8856b6dd90e0101c","repo":"microsoft/aspire","slug":"could-not-create-http-command-for-resource-builder-resource-8856b6","errorCode":null,"errorMessage":"Could not create HTTP command for resource '{builder.Resource.Name}' as the endpoint with name '{endpoint.EndpointName}' and scheme '{endpoint.Scheme}' is not an HTTP endpoint.","messagePattern":"Could not create HTTP command for resource '(.+?)' as the endpoint with name '(.+?)' and scheme '(.+?)' is not an HTTP endpoint\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ResourceBuilderExtensions.cs","lineNumber":3688,"sourceCode":"    /// </remarks>\n    [AspireExportIgnore(Reason = \"Use the ATS-specific withHttpCommand export.\")]\n    public static IResourceBuilder<TResource> WithHttpCommand<TResource>(\n        this IResourceBuilder<TResource> builder,\n        string path,\n        string displayName,\n        Func<EndpointReference>? endpointSelector,\n        string? commandName = null,\n        HttpCommandOptions? commandOptions = null)\n        where TResource : IResourceWithEndpoints\n    {\n        endpointSelector ??= DefaultEndpointSelector(builder);\n\n        var endpoint = endpointSelector()\n            ?? throw new DistributedApplicationException($\"Could not create HTTP command for resource '{builder.Resource.Name}' as the endpoint selector returned null.\");\n\n        if (endpoint.Scheme != \"http\" && endpoint.Scheme != \"https\")\n        {\n            throw new DistributedApplicationException($\"Could not create HTTP command for resource '{builder.Resource.Name}' as the endpoint with name '{endpoint.EndpointName}' and scheme '{endpoint.Scheme}' is not an HTTP endpoint.\");\n        }\n\n        builder.ApplicationBuilder.Services.AddHttpClient();\n\n        commandOptions ??= HttpCommandOptions.Default;\n        commandOptions.Method ??= HttpMethod.Post;\n\n        commandName ??= $\"{endpoint.Resource.Name}-{endpoint.EndpointName}-http-{commandOptions.Method.Method.ToLowerInvariant()}-{path}\";\n\n        if (commandOptions.UpdateState is null)\n        {\n            commandOptions.UpdateState = context =>\n            {\n                var resourceState = context.ResourceSnapshot.State?.Text;\n                var targetRunning = resourceState == KnownResourceStates.Running || resourceState == KnownResourceStates.RuntimeUnhealthy;\n                return targetRunning ? ResourceCommandState.Enabled : ResourceCommandState.Disabled;\n            };\n        }","sourceCodeStart":3670,"sourceCodeEnd":3706,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L3670-L3706","documentation":"After the endpoint selector resolves an endpoint, Aspire verifies the endpoint's scheme is http or https before wiring an HTTP command. An endpoint with any other scheme (tcp, custom schemes) cannot be addressed with an HttpRequestMessage, so it throws DistributedApplicationException identifying the endpoint name and scheme.","triggerScenarios":"Creating an HTTP command (WithHttpCommand-style API) whose selector returns an endpoint declared with a non-HTTP scheme, e.g. WithEndpoint(name: \"admin\", scheme: \"tcp\") or a custom scheme registered via WithEndpoint(scheme: ...).","commonSituations":"Selecting an endpoint by name that was defined for raw TCP or another protocol; scheme typos like 'htps'; endpoints shared between an HTTP command and a non-HTTP health probe.","solutions":["Point the selector at an endpoint declared with scheme http or https","Change the endpoint declaration to use http/https if the endpoint really serves HTTP","If the endpoint is intentionally non-HTTP, use a process command instead of an HTTP command"],"exampleFix":"// before\nvar ep = resource.GetEndpoint(\"metrics\"); // declared scheme: \"tcp\"\n// after\nvar ep = resource.GetEndpoint(\"http\"); // endpoint declared with scheme \"http\"","handlingStrategy":"validation","validationCode":"var ep = selector();\nif (ep is not null && ep.Scheme is not (\"http\" or \"https\"))\n    throw new InvalidOperationException($\"Endpoint '{ep.EndpointName}' must be http/https, was '{ep.Scheme}'\");","typeGuard":"bool IsHttpEndpoint(EndpointReference? ep) => ep?.Scheme is \"http\" or \"https\";","tryCatchPattern":"try { builder.WithHttpCommand(...); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"is not an HTTP endpoint\")) { /* reselect or redeclare endpoint */ }","preventionTips":["Restrict custom selectors to http/https schemes","Keep endpoint scheme declarations consistent with how they are consumed"],"tags":["http","endpoint","scheme","aspire-hosting"],"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"}