{"record":{"id":"af7dff94aab4162b","repo":"microsoft/aspire","slug":"unsupported-json-value-kind-element-valuekind","errorCode":null,"errorMessage":"Unsupported JSON value kind '{element.ValueKind}'.","messagePattern":"Unsupported JSON value kind '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs","lineNumber":231,"sourceCode":"    {\n        using var document = JsonDocument.Parse(node.ToJsonString());\n\n        return NormalizeJsonElement(document.RootElement);\n    }\n\n    private static object? NormalizeJsonElement(JsonElement element)\n    {\n        return element.ValueKind switch\n        {\n            JsonValueKind.Null => null,\n            JsonValueKind.String => element.GetString(),\n            JsonValueKind.True => true,\n            JsonValueKind.False => false,\n            JsonValueKind.Number when element.TryGetInt64(out var longValue) => longValue,\n            JsonValueKind.Number => element.GetDouble(),\n            JsonValueKind.Array => element.EnumerateArray().Select(NormalizeJsonElement).ToList(),\n            JsonValueKind.Object => element.EnumerateObject().ToDictionary(prop => prop.Name, prop => NormalizeJsonElement(prop.Value), StringComparer.Ordinal),\n            _ => throw new ArgumentException($\"Unsupported JSON value kind '{element.ValueKind}'.\", nameof(element))\n        };\n    }\n\n    private static Dictionary<string, object?> NormalizeDictionary(IDictionary dictionary)\n    {\n        var result = new Dictionary<string, object?>(StringComparer.Ordinal);\n\n        foreach (DictionaryEntry entry in dictionary)\n        {\n            if (entry.Key is not string key)\n            {\n                throw new ArgumentException(\"Manifest field dictionaries must use string keys.\");\n            }\n\n            result[key] = NormalizeManifestValue(entry.Value);\n        }\n\n        return result;","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesManifestResource.cs#L213-L249","documentation":"A JsonElement passed as a manifest field has a ValueKind the normalizer does not handle — in practice JsonValueKind.Undefined (or a kind outside the handled set of Null, True, False, Number, Array, Object, String). The library throws an ArgumentException because the JSON value cannot be emitted into the manifest.","triggerScenarios":"Calling WithField with a JsonElement/JsonNode whose ValueKind is Undefined, typically obtained from JsonDocument.Parse of invalid or partial data, default(JsonElement), or a property that was skipped/removed from a JsonDocument.","commonSituations":"Parsing JSON with JsonDocumentOptions allowing malformed input, reading properties that don't exist, reusing a disposed JsonDocument, or passing default(JsonElement) as a placeholder. JsonNode can also wrap null kinds that degrade to Undefined.","solutions":["Check element.ValueKind != JsonValueKind.Undefined before passing the JsonElement to WithField","Ensure the JsonDocument the element came from is still alive and was parsed successfully without JsonCommentHandling/invalid-JSON leniency that yields Undefined","Replace default(JsonElement) placeholders with JsonValueKind.Null ( JsonSerializer.SerializeToElement((object?)null) )"],"exampleFix":"// before\nusing var doc = JsonDocument.Parse(maybeJson);\nmanifest.WithField(\"spec.config\", doc.RootElement.GetProperty(\"missing\")); // may be Undefined\n// after\nusing var doc = JsonDocument.Parse(maybeJson);\nif (doc.RootElement.TryGetProperty(\"missing\", out var el) && el.ValueKind != JsonValueKind.Undefined)\n{\n    manifest.WithField(\"spec.config\", el);\n}","handlingStrategy":"type-guard","validationCode":"if (element.ValueKind is JsonValueKind.Undefined) throw new InvalidOperationException(\"JSON element is Undefined and cannot be a manifest field.\");","typeGuard":"static bool IsWellFormedJsonElement(JsonElement e) => e.ValueKind is not JsonValueKind.Undefined;","tryCatchPattern":"try { manifest.WithField(path, element); } catch (ArgumentException ex) when (ex.Message.Contains(\"Unsupported JSON value kind\")) { manifest.WithField(path, (string?)null); }","preventionTips":["Check TryGetProperty before accessing members and verify ValueKind != Undefined","Keep the owning JsonDocument alive while the element is in use","Never pass default(JsonElement); use JsonSerializer.SerializeToElement(null) for JSON null"],"tags":["kubernetes","manifest","json","valuekind"],"backgroundTag":"json-serialization-failed","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"}