microsoft/aspire · error · NotSupportedException

KubernetesManifestResource does not support YAML…

Error message

KubernetesManifestResource does not support YAML deserialization.

What it means

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.

Solutions

  1. 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.
  2. If you need a manifest inside Aspire, add it as a file/command resource or use KubernetesManifestResource APIs to construct it in code.
  3. Wrap deserialization calls in a try-catch for NotSupportedException only if you must probe capability, but prefer removing the deserialization path entirely.

Example fix

// before
var resource = new DeserializerBuilder()...
    .WithConverter(new KubernetesManifestResourceYamlConverter())
    .Deserialize<KubernetesManifestResource>(yaml);
// after
var doc = new DeserializerBuilder().Build().Deserialize<Dictionary<string, object>>(yaml);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof(KubernetesManifestResource) == targetType) throw new NotSupportedException("Deserialize into a POCO/DTO instead of KubernetesManifestResource.");

Type guard

static bool CanDeserialize(Type t) => t != typeof(KubernetesManifestResource);

Try / catch

try { return deserializer.Deserialize<KubernetesManifestResource>(yaml); } catch (NotSupportedException) { return deserializer.Deserialize<Dictionary<string, object>>(yaml); }

Prevention

When it happens

Trigger: Calling YamlDotNet Deserializer.Deserialize<KubernetesManifestResource>(...) or otherwise routing a read through this converter (src/Aspire.Hosting.Kubernetes/Yaml/KubernetesManifestResourceYamlConverter.cs:19).

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/d2bdcd87f4b76c90. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Kubernetes/Yaml/KubernetesManifestResourceYamlConverter.cs:19

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;

namespace Aspire.Hosting.Kubernetes.Yaml;

internal sealed class KubernetesManifestResourceYamlConverter : IYamlTypeConverter
{
    public bool Accepts(Type type)
    {
        return type == typeof(KubernetesManifestResource);
    }

    public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
    {
        throw new NotSupportedException($"{nameof(KubernetesManifestResource)} does not support YAML deserialization.");
    }

    public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
    {
        if (value is not KubernetesManifestResource manifest)
        {
            throw new InvalidOperationException($"Expected {nameof(KubernetesManifestResource)} but got {value?.GetType()}.");
        }

        emitter.Emit(new MappingStart());

        WriteProperty("apiVersion", manifest.ApiVersion, serializer);
        WriteProperty("kind", manifest.Kind, serializer);
        WriteProperty("metadata", manifest.Metadata, serializer);

        foreach (var (key, fieldValue) in manifest.Fields)
        {
            WriteProperty(key, fieldValue, serializer);

View on GitHub (pinned to 25830f84bd)