{"record":{"id":"d14d991f7185dd60","repo":"microsoft/aspire","slug":"the-foundry-local-endpoint-must-be-an-absolute-http-or-https","errorCode":null,"errorMessage":"The Foundry Local endpoint must be an absolute HTTP or HTTPS URL.","messagePattern":"The Foundry Local endpoint must be an absolute HTTP or HTTPS URL\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/FoundryExtensions.cs","lineNumber":215,"sourceCode":"    [AspireExport]\n    public static IResourceBuilder<FoundryResource> RunAsFoundryLocal(\n        this IResourceBuilder<FoundryResource> builder,\n        string? endpoint = null)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n\n        if (builder.ApplicationBuilder.ExecutionContext.IsPublishMode)\n        {\n            return builder;\n        }\n\n        Uri? existingEndpoint = null;\n        if (endpoint is not null)\n        {\n            if (!Uri.TryCreate(endpoint, UriKind.Absolute, out existingEndpoint) ||\n                existingEndpoint.Scheme is not (\"http\" or \"https\"))\n            {\n                throw new ArgumentException(\"The Foundry Local endpoint must be an absolute HTTP or HTTPS URL.\", nameof(endpoint));\n            }\n\n            existingEndpoint = EnsureTrailingSlash(existingEndpoint);\n        }\n\n        var resource = builder.Resource;\n        ThrowIfProjectsConfiguredForLocal(builder, resource);\n        resource.Annotations.Add(new EmulatorResourceAnnotation());\n        resource.ApiKey = FoundryLocalService.ApiKey;\n        resource.EmulatorServiceUri = existingEndpoint;\n        resource.ManageLocalService = existingEndpoint is null;\n\n        builder.WithInitializer();\n        if (resource.ManageLocalService)\n        {\n            builder.OnResourceStopped(static (_, _, ct) => FoundryLocalService.StopAsync(ct));\n            builder.ApplicationBuilder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, FoundryLocalLifecycleService>());\n        }","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L197-L233","documentation":"RunAsFoundryLocal configures a Foundry resource to run against a local Foundry Local service. If an explicit endpoint string is supplied, it must parse as an absolute URI with scheme http or https; anything else (relative URL, missing scheme, wrong scheme like ftp or ws) throws this ArgumentException.","triggerScenarios":"builder.AddFoundry(...).RunAsFoundryLocal(endpoint: \"localhost:8080\") or endpoint: \"ftp://host\" — a string that is not an absolute http/https URL.","commonSituations":"Forgetting the http:// scheme prefix; using a ws:// or https-rel path; environment variable containing a malformed URL; trailing config typos.","solutions":["Prefix the endpoint with http:// or https:// and ensure it is fully qualified","Validate with Uri.TryCreate(uriString, UriKind.Absolute, out var u) and u.Scheme is \"http\" or \"https\" before passing","Fix the environment/config value supplying the endpoint"],"exampleFix":"// before\n.RunAsFoundryLocal(endpoint: \"localhost:5100\");\n// after\n.RunAsFoundryLocal(endpoint: \"http://localhost:5100\");","handlingStrategy":"validation","validationCode":"bool IsValidEndpoint(string? e) =>\n    Uri.TryCreate(e, UriKind.Absolute, out var u) && u.Scheme is \"http\" or \"https\";","typeGuard":null,"tryCatchPattern":"try { foundry.RunAsFoundryLocal(endpoint); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"absolute HTTP or HTTPS\")) { /* fix the URL */ }","preventionTips":["Always store Foundry Local endpoints as fully qualified absolute URLs with scheme","Validate config-sourced URLs with Uri.TryCreate(UriKind.Absolute) before passing","Watch for env-var values that omit the scheme"],"tags":["azure-foundry","url","validation"],"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"}