{"record":{"id":"40e0236c20e94df9","repo":"microsoft/aspire","slug":"browsermessagestrings-browserlogsresourcemissinghttpendpoint","errorCode":null,"errorMessage":"BrowserMessageStrings.BrowserLogsResourceMissingHttpEndpoint","messagePattern":"BrowserMessageStrings\\.BrowserLogsResourceMissingHttpEndpoint","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Browsers/BrowserLogsBuilderExtensions.cs","lineNumber":330,"sourceCode":"                new ResourcePropertySnapshot(BrowserSessionsPropertyName, \"[]\"),\n                new ResourcePropertySnapshot(TotalSessionsLaunchedPropertyName, 0)\n            ]);\n\n            return [.. properties];\n        }\n\n        static Uri ResolveBrowserUrl(T resource)\n        {\n            EndpointAnnotation? endpointAnnotation = null;\n            if (resource.TryGetAnnotationsOfType<EndpointAnnotation>(out var endpoints))\n            {\n                endpointAnnotation = endpoints.FirstOrDefault(e => e.UriScheme == \"https\")\n                    ?? endpoints.FirstOrDefault(e => e.UriScheme == \"http\");\n            }\n\n            if (endpointAnnotation is null)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsResourceMissingHttpEndpoint, resource.Name));\n            }\n\n            var endpointReference = resource.GetEndpoint(endpointAnnotation.Name);\n            if (!endpointReference.IsAllocated)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, BrowserMessageStrings.BrowserLogsEndpointNotAllocated, endpointAnnotation.Name, resource.Name));\n            }\n\n            return new Uri(endpointReference.Url, UriKind.Absolute);\n        }\n\n        static void ThrowIfBlankWhenSpecified(string? value, string paramName)\n        {\n            if (value is not null)\n            {\n                ArgumentException.ThrowIfNullOrWhiteSpace(value, paramName);\n            }\n        }","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Browsers/BrowserLogsBuilderExtensions.cs#L312-L348","documentation":"WithBrowserLogs requires the target resource to expose an HTTP or HTTPS endpoint; the builder scans the resource's EndpointAnnotations (preferring https, falling back to http) to derive the URL for the tracked browser. If no endpoint with either scheme exists, it throws this InvalidOperationException naming the resource.","triggerScenarios":"Calling builder.WithBrowserLogs(...) on a resource that has no http/https endpoint — e.g. a worker/process resource, a database, or a web project that never declared WithEndpoint/WithHttpEndpoint.","commonSituations":"Applying WithBrowserLogs to a non-HTTP resource by mistake; a frontend project missing its endpoint declaration; endpoint defined with a custom scheme (tcp, ws) instead of http/https.","solutions":["Add an http or https endpoint to the resource (WithHttpEndpoint / WithEndpoint with UriScheme http(s)).","Apply WithBrowserLogs to the actual web project resource instead of a non-HTTP resource.","If using a custom endpoint, set its scheme to http or https."],"exampleFix":"// before\nvar frontend = builder.AddProject<Projects.Frontend>(\"frontend\").WithBrowserLogs(); // no endpoint declared\n\n// after\nvar frontend = builder.AddProject<Projects.Frontend>(\"frontend\")\n    .WithHttpEndpoint(port: 5000)\n    .WithBrowserLogs();","handlingStrategy":"validation","validationCode":"// Confirm the resource exposes an http/https endpoint before enabling browser logs\nbool HasHttpEndpoint(IResource r) => r.Annotations.OfType<EndpointAnnotation>()\n    .Any(e => e.UriScheme is \"http\" or \"https\");\nif (!HasHttpEndpoint(frontend)) throw new InvalidOperationException(\"WithBrowserLogs requires an http/https endpoint.\");","typeGuard":null,"tryCatchPattern":"try { frontend.WithBrowserLogs(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"endpoint\", StringComparison.OrdinalIgnoreCase)) { logger.LogError(ex, \"Resource {Name} has no http/https endpoint for browser logs.\", frontend.Resource.Name); }","preventionTips":["Always declare WithHttpEndpoint/WithEndpoint on resources you attach WithBrowserLogs to.","Only apply WithBrowserLogs to web resources, not workers or databases.","Keep endpoint schemes as http/https for browser-facing resources."],"tags":["endpoint","configuration","http","aspire-hosting"],"backgroundTag":"resource-not-found","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"}