{"record":{"id":"d2bdcd87f4b76c90","repo":"microsoft/aspire","slug":"kubernetesmanifestresource-does-not-support-yaml","errorCode":null,"errorMessage":"KubernetesManifestResource does not support YAML deserialization.","messagePattern":"KubernetesManifestResource does not support YAML deserialization\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/Yaml/KubernetesManifestResourceYamlConverter.cs","lineNumber":19,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nusing YamlDotNet.Core;\nusing YamlDotNet.Core.Events;\nusing YamlDotNet.Serialization;\n\nnamespace Aspire.Hosting.Kubernetes.Yaml;\n\ninternal sealed class KubernetesManifestResourceYamlConverter : IYamlTypeConverter\n{\n    public bool Accepts(Type type)\n    {\n        return type == typeof(KubernetesManifestResource);\n    }\n\n    public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)\n    {\n        throw new NotSupportedException($\"{nameof(KubernetesManifestResource)} does not support YAML deserialization.\");\n    }\n\n    public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)\n    {\n        if (value is not KubernetesManifestResource manifest)\n        {\n            throw new InvalidOperationException($\"Expected {nameof(KubernetesManifestResource)} but got {value?.GetType()}.\");\n        }\n\n        emitter.Emit(new MappingStart());\n\n        WriteProperty(\"apiVersion\", manifest.ApiVersion, serializer);\n        WriteProperty(\"kind\", manifest.Kind, serializer);\n        WriteProperty(\"metadata\", manifest.Metadata, serializer);\n\n        foreach (var (key, fieldValue) in manifest.Fields)\n        {\n            WriteProperty(key, fieldValue, serializer);","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/Yaml/KubernetesManifestResourceYamlConverter.cs#L1-L37","documentation":"KubernetesManifestResourceYamlConverter supports writing KubernetesManifestResource objects to YAML but explicitly refuses to read them back. ReadYaml always throws NotSupportedException because manifest resources are generated from the app model, not parsed from YAML. Round-tripping YAML into an Aspire KubernetesManifestResource is intentionally not implemented.","triggerScenarios":"Calling YamlDotNet Deserializer.Deserialize<KubernetesManifestResource>(...) or otherwise routing a read through this converter (src/Aspire.Hosting.Kubernetes/Yaml/KubernetesManifestResourceYamlConverter.cs:19).","commonSituations":"Attempting to load an existing Kubernetes YAML manifest into the Aspire app model; a tooling script that re-parses previously emitted YAML expecting symmetry with the serializer; tests that assume deserialization works.","solutions":["Do not deserialize into KubernetesManifestResource; use YamlDotNet's generic deserializer with a plain POCO model (e.g. Dictionary<string, object> or a Kubernetes-object DTO) instead.","If you need a manifest inside Aspire, add it as a file/command resource or use KubernetesManifestResource APIs to construct it in code.","Wrap deserialization calls in a try-catch for NotSupportedException only if you must probe capability, but prefer removing the deserialization path entirely."],"exampleFix":"// before\nvar resource = new DeserializerBuilder()...\n    .WithConverter(new KubernetesManifestResourceYamlConverter())\n    .Deserialize<KubernetesManifestResource>(yaml);\n// after\nvar doc = new DeserializerBuilder().Build().Deserialize<Dictionary<string, object>>(yaml);","handlingStrategy":"validation","validationCode":"if (typeof(KubernetesManifestResource) == targetType) throw new NotSupportedException(\"Deserialize into a POCO/DTO instead of KubernetesManifestResource.\");","typeGuard":"static bool CanDeserialize(Type t) => t != typeof(KubernetesManifestResource);","tryCatchPattern":"try { return deserializer.Deserialize<KubernetesManifestResource>(yaml); } catch (NotSupportedException) { return deserializer.Deserialize<Dictionary<string, object>>(yaml); }","preventionTips":["Never deserialize into KubernetesManifestResource; use a DTO or Dictionary<string, object>","Remember the manifest converter is write-only by design","Document YAML round-trip asymmetry in team tooling"],"tags":["yaml","deserialization","kubernetes","not-supported"],"backgroundTag":"unsupported-operation","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"}