{"record":{"id":"a4e6cf62f7c32909","repo":"microsoft/aspire","slug":"could-not-create-http-probe-for-resource-builder-resource","errorCode":null,"errorMessage":"Could not create HTTP probe for resource '{builder.Resource.Name}' as the endpoint selector returned null.","messagePattern":"Could not create HTTP probe for resource '(.+?)' as the endpoint selector returned null\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ResourceBuilderExtensions.cs","lineNumber":5115,"sourceCode":"    ///     .WithHttpProbe(ProbeType.Liveness, \"/health\");\n    /// </code>\n    /// Is the same of writing:\n    /// <code lang=\"C#\">\n    /// var service = builder.AddProject&lt;Projects.MyService&gt;(\"service\")\n    ///     .WithHttpProbe(ProbeType.Liveness, \"/health\")\n    ///     .WithHttpHealthCheck(\"/health\");\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    [Experimental(\"ASPIREPROBES001\", UrlFormat = \"https://aka.ms/aspire/diagnostics/{0}\")]\n    [AspireExportIgnore(Reason = \"Func<EndpointReference> delegate — not ATS-compatible.\")]\n    public static IResourceBuilder<T> WithHttpProbe<T>(this IResourceBuilder<T> builder, ProbeType type, Func<EndpointReference>? endpointSelector, string? path = null, int? initialDelaySeconds = null, int? periodSeconds = null, int? timeoutSeconds = null, int? failureThreshold = null, int? successThreshold = null)\n        where T : IResourceWithEndpoints, IResourceWithProbes\n    {\n        endpointSelector ??= DefaultEndpointSelector(builder);\n\n        var endpoint = endpointSelector() ?? throw new DistributedApplicationException($\"Could not create HTTP probe for resource '{builder.Resource.Name}' as the endpoint selector returned null.\");\n        var endpointProbeAnnotation = new EndpointProbeAnnotation\n        {\n            Type = type,\n            EndpointReference = endpoint,\n            Path = path ?? \"/\",\n            InitialDelaySeconds = initialDelaySeconds ?? 5,\n            PeriodSeconds = periodSeconds ?? 5,\n            TimeoutSeconds = timeoutSeconds ?? 1,\n            FailureThreshold = failureThreshold ?? 3,\n            SuccessThreshold = successThreshold ?? 1,\n        };\n\n        return builder\n            .WithProbe(endpointProbeAnnotation)\n            .WithHttpHealthCheck(endpointSelector, path);\n    }\n\n    /// <summary>","sourceCodeStart":5097,"sourceCodeEnd":5133,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ResourceBuilderExtensions.cs#L5097-L5133","documentation":"WithHttpProbe creates an HTTP probe (liveness/readiness/startup) for a resource by asking an endpoint selector for an EndpointReference. This DistributedApplicationException is thrown when that selector returns null, meaning there is no endpoint from which to build the probe. It guards against creating a probe annotation pointing at a nonexistent endpoint.","triggerScenarios":"Calling WithHttpProbe with a custom endpointSelector delegate that returns null, or with the default selector when the resource has no matching HTTP endpoint. Passing null for endpointSelector uses DefaultEndpointSelector, which can still yield null.","commonSituations":"Adding probes to a resource before any endpoint is registered, a selector filtering on an endpoint name/scheme that does not exist, or conditional endpoint registration (publish-only endpoints).","solutions":["Ensure the resource has an HTTP endpoint registered (WithHttpEndpoint/WithHttpsEndpoint) before WithHttpProbe","Fix or remove the custom endpointSelector so it returns a valid EndpointReference","Check the endpoint exists in both run and publish modes if endpoints are conditional"],"exampleFix":"// before\nvar api = builder.AddProject<Projects.Api>(\"api\")\n    .WithHttpProbe(ProbeType.Readiness, selector: e => null);\n// after\nvar api = builder.AddProject<Projects.Api>(\"api\")\n    .WithHttpEndpoint(port: 8080)\n    .WithHttpProbe(ProbeType.Readiness, path: \"/health\");","handlingStrategy":"validation","validationCode":"EndpointReference? SelectEndpoint(IResourceBuilder<T> b) =>\n    b.Resource.Annotations.OfType<EndpointAnnotation>().Any()\n        ? b.GetEndpoint(\"http\")\n        : null;\nif (SelectEndpoint(builder) is null) throw new InvalidOperationException(\"Resource has no endpoint for probes.\");","typeGuard":null,"tryCatchPattern":"try { builder.WithHttpProbe(ProbeType.Readiness); }\ncatch (DistributedApplicationException ex) { logger.LogWarning(ex, \"Probe skipped for {Resource}: no endpoint\", builder.Resource.Name); }","preventionTips":["Register endpoints before adding probes","Verify custom endpointSelector delegates return non-null for all launch modes","Prefer the default selector only when the resource certainly has an HTTP endpoint"],"tags":["aspire","http","probes","endpoints"],"backgroundTag":"null-argument","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"}