{"record":{"id":"ddb50e1036dcbaee","repo":"microsoft/aspire","slug":"could-not-create-http-health-check-for-resource-builder-ddb50e","errorCode":null,"errorMessage":"Could not create HTTP health check 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 health check 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":2813,"sourceCode":"    /// var backend = builder.AddProject&lt;Projects.Backend&gt;(\"backend\");\n    /// backend.WithHttpHealthCheck(() => backend.GetEndpoint(\"https\"), path: \"/health\")\n    /// builder.AddProject&lt;Projects.Frontend&gt;(\"frontend\")\n    ///        .WithReference(backend).WaitFor(backend);\n    /// </code>\n    /// </example>\n    /// <para>This method is not available in polyglot app hosts. Use the endpointName-based overload instead.</para>\n    /// </remarks>\n    [AspireExportIgnore(Reason = \"Func<EndpointReference> delegate — not ATS-compatible.\")]\n    public static IResourceBuilder<T> WithHttpHealthCheck<T>(this IResourceBuilder<T> builder, Func<EndpointReference>? endpointSelector, string? path = null, int? statusCode = null) where T : IResourceWithEndpoints\n    {\n        endpointSelector ??= DefaultEndpointSelector(builder);\n\n        var endpoint = endpointSelector()\n            ?? throw new DistributedApplicationException($\"Could not create HTTP health check 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 health check for resource '{builder.Resource.Name}' as the endpoint with name '{endpoint.EndpointName}' and scheme '{endpoint.Scheme}' is not an HTTP endpoint.\");\n        }\n\n        path ??= \"/\";\n        statusCode ??= 200;\n\n        var endpointName = endpoint.EndpointName;\n\n        // Validate that the endpoint exists during allocation to fail fast on misconfiguration.\n        builder.OnResourceEndpointsAllocated((_, @event, ct) =>\n        {\n            if (!endpoint.Exists)\n            {\n                throw new DistributedApplicationException($\"The endpoint '{endpointName}' does not exist on the resource '{builder.Resource.Name}'.\");\n            }\n\n            return Task.CompletedTask;\n        });\n","sourceCodeStart":2795,"sourceCodeEnd":2831,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L2795-L2831","documentation":"Thrown by WithHttpHealthCheck when the selected endpoint's scheme is neither http nor https. The health check performs an HTTP GET, so only HTTP(S) endpoints are valid; other schemes (e.g. tcp) cannot be probed this way.","triggerScenarios":"Calling WithHttpHealthCheck (explicitly or via default selector) on a resource whose matching endpoint was declared with a non-HTTP scheme, e.g. WithEndpoint(name: \"tcp\", scheme: \"tcp\").","commonSituations":"Resources with mixed endpoints where the default selector picks the wrong (TCP) endpoint; copy-pasted health-check wiring onto a database/cache TCP endpoint; endpoint renamed so the default resolves to the wrong one.","solutions":["Pass the explicit HTTP endpoint name: WithHttpHealthCheck(\"http\").","Declare an HTTP endpoint with WithHttpEndpoint (scheme http/https) on the resource.","Use WithHealthCheck with a custom IHealthCheck for non-HTTP protocols instead.","Check the endpoint's Scheme property in the AppHost before wiring."],"exampleFix":"// before\nvar redis = builder.AddRedis(\"redis\"); // has tcp endpoint only\nredis.WithHttpHealthCheck(); // throws: scheme 'tcp'\n\n// after\nvar api = builder.AddProject<Projects.Api>(\"api\")\n    .WithHttpEndpoint(name: \"http\");\napi.WithHttpHealthCheck(\"http\");","handlingStrategy":"validation","validationCode":"var ep = resource.Annotations.OfType<EndpointAnnotation>()\n    .FirstOrDefault(e => e.Scheme is \"http\" or \"https\");\nif (ep is null)\n    throw new InvalidOperationException(\"WithHttpHealthCheck requires an http/https endpoint.\");","typeGuard":"bool IsHttpScheme(EndpointReference e) => e.Scheme is \"http\" or \"https\";","tryCatchPattern":"try { api.WithHttpHealthCheck(\"http\"); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"is not an HTTP endpoint\"))\n{ Console.Error.WriteLine(ex.Message); throw; }","preventionTips":["Pass the explicit HTTP endpoint name to WithHttpHealthCheck instead of relying on defaults.","Use WithHttpEndpoint for endpoints intended for HTTP health probes.","For TCP/other protocols, use a custom IHealthCheck via WithHealthCheck."],"tags":["aspire","health-check","endpoint","scheme"],"backgroundTag":"invalid-url-format","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"}