{"record":{"id":"321e1f3e6505d2c9","repo":"microsoft/aspire","slug":"manifest-field-path-must-contain-at-least-one-segment","errorCode":null,"errorMessage":"Manifest field path must contain at least one segment.","messagePattern":"Manifest field path must contain at least one segment\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs","lineNumber":103,"sourceCode":"    public KubernetesManifestResource WithField(\n        string path,\n        [AspireUnion(typeof(string), typeof(double), typeof(bool))] object value)\n    {\n        var segments = ParseFieldPath(path);\n\n        SetField(Fields, segments, path, NormalizeManifestValue(value));\n\n        return this;\n    }\n\n    private static string[] ParseFieldPath(string path)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(path);\n\n        var segments = path.Split('.', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);\n        if (segments.Length == 0)\n        {\n            throw new ArgumentException(\"Manifest field path must contain at least one segment.\", nameof(path));\n        }\n\n        if (segments[0] is \"apiVersion\" or \"kind\" or \"metadata\")\n        {\n            throw new ArgumentException(\"Use the dedicated manifest API to configure apiVersion, kind, and metadata fields.\", nameof(path));\n        }\n\n        return segments;\n    }\n\n    private static void SetField(Dictionary<string, object?> fields, ReadOnlySpan<string> segments, string path, object? value)\n    {\n        var current = fields;\n\n        for (var i = 0; i < segments.Length - 1; i++)\n        {\n            var segment = segments[i];\n            if (current.TryGetValue(segment, out var child))","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs#L85-L121","documentation":"ParseFieldPath splits a dotted manifest field path (e.g. \"spec.replicas\") into segments and requires at least one non-empty segment. It throws ArgumentException when the path is null, whitespace-only, or composed entirely of dots, since there would be no field to address.","triggerScenarios":"Calling WithField/manifest field APIs with an empty string, whitespace, or a path like \"...\"; passing a string variable that was never initialized from config.","commonSituations":"Field path read from a config value or JSON key that is empty in the current environment; a typo leaving a constant empty; string interpolation producing only separators.","solutions":["Pass a non-empty dotted path such as \"spec.replicas\" to the manifest field API.","Validate the configured path string (not null/whitespace) before calling WithField.","Trim surrounding whitespace and remove accidental leading/trailing dots from the path before use."],"exampleFix":"// before\nresource.WithField(path, value); // path == \"\"\n// after\nif (string.IsNullOrWhiteSpace(path))\n{\n    throw new InvalidOperationException(\"Manifest field path is not configured.\");\n}\nresource.WithField(path, value);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(path) || path.Split('.', StringSplitOptions.RemoveEmptyEntries).Length == 0)\n{\n    throw new ArgumentException(\"Field path must name at least one segment, e.g. 'spec.replicas'.\", nameof(path));\n}","typeGuard":"static bool IsValidFieldPath(string? path) =>\n    !string.IsNullOrWhiteSpace(path) && path.Split('.', StringSplitOptions.RemoveEmptyEntries).Length > 0;","tryCatchPattern":"try\n{\n    resource.WithField(path, value);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"at least one segment\"))\n{\n    // path was null/whitespace/all dots; fix configuration and rethrow or default\n}","preventionTips":["Store field paths as constants instead of raw strings from config.","Validate config-sourced paths at startup, before building the model.","Strip stray whitespace and dots from paths sourced from user configuration."],"tags":["kubernetes","manifest","argument","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}