{"record":{"id":"fe4ed863bddf3aa6","repo":"microsoft/aspire","slug":"path-must-start-with-kubernetesingressextensions","errorCode":null,"errorMessage":"Path must start with '/'.","messagePattern":"Path must start with '/'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesIngressExtensions.cs","lineNumber":131,"sourceCode":"    /// <code>\n    /// var api = builder.AddProject&lt;MyApi&gt;(\"api\");\n    /// ingress.WithPath(\"/api\", api.GetEndpoint(\"http\"));\n    /// </code>\n    /// </example>\n    [AspireExport(\"withIngressPath\")]\n    public static IResourceBuilder<KubernetesIngressResource> WithPath(\n        this IResourceBuilder<KubernetesIngressResource> builder,\n        string path,\n        EndpointReference endpoint,\n        IngressPathType pathType = IngressPathType.Prefix)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(path);\n        ArgumentNullException.ThrowIfNull(endpoint);\n\n        if (!path.StartsWith('/'))\n        {\n            throw new ArgumentException(\"Path must start with '/'.\", nameof(path));\n        }\n\n        builder.Resource.Paths.Add(new IngressPathConfig(\n            Host: null,\n            Path: path,\n            PathType: pathType,\n            Endpoint: endpoint));\n\n        return builder;\n    }\n\n    /// <summary>\n    /// Adds a host-scoped path rule to the ingress. The rule matches traffic for the\n    /// specified host and path, forwarding it to the given endpoint's backing Kubernetes service.\n    /// </summary>\n    /// <param name=\"builder\">The ingress resource builder.</param>\n    /// <param name=\"host\">The hostname to match (e.g., <c>\"api.example.com\"</c>).</param>\n    /// <param name=\"path\">The URL path to match (e.g., <c>\"/\"</c> or <c>\"/api\"</c>). Must start with <c>/</c>.</param>","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesIngressExtensions.cs#L113-L149","documentation":"Kubernetes Ingress path rules must begin with '/' per the Ingress spec. Aspire's WithPath extension on a Kubernetes ingress resource validates the path before adding it to the resource's Paths collection and throws this ArgumentException for paths without the leading slash.","triggerScenarios":"Calling the host-less WithPath overload on a Kubernetes ingress with a path like 'api' or 'api/v1' (no leading '/'), or an empty-after-normalization string that passes ThrowIfNullOrEmpty but fails the slash check.","commonSituations":"Copy-pasting route templates from frameworks that omit the leading slash; building paths dynamically with string concatenation that dropped the separator; confusing Ingress paths with relative URL paths in client code.","solutions":["Prefix the path with '/', e.g. '/api/v1'.","If building paths dynamically, ensure segments are joined with a leading '/'.","Leave the path as the Ingress-specified absolute form; Kubernetes does not support relative paths.","If you intended regex or ExactPrefix path types, the path still must start with '/'."],"exampleFix":"// before\ningress.WithPath(\"api/v1\");\n// after\ningress.WithPath(\"/api/v1\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path) || !path.StartsWith('/'))\n    throw new ArgumentException(\"Ingress path must start with '/'\");","typeGuard":null,"tryCatchPattern":"try { ingress.WithPath(path); }\ncatch (ArgumentException ex) when (ex.Message == \"Path must start with '/'.\")\n{ logger.LogError(ex, \"Ingress path '{Path}' must be absolute\", path); }","preventionTips":["Always define ingress paths as absolute, beginning with '/'.","Normalize route configuration at load time (prepend '/' when missing).","Don't reuse relative URL route templates from app frameworks directly as ingress paths."],"tags":["kubernetes","ingress","validation","path"],"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"}