microsoft/aspire · error · InvalidOperationException

Unknown resource type

Error message

Unknown resource type {resource.GetType().Name}

What it means

GetResourceType maps an application-model resource to its DCP kind via a switch over Container/Executable/ContainerExec; any other DCP resource type falls through to an InvalidOperationException. It is an internal completeness guard: the executor encountered a DCP object it does not know how to classify.

Solutions

  1. Update to matching versions of all Aspire.* packages so DCP object kinds align.
  2. If you wrote a custom resource/DCP object, extend the mapping to emit a supported kind (Container, Executable, or ContainerExec).
  3. Check third-party hosting integrations for a newer version supporting your resource type.
  4. Report the resource type name shown in the message to the integration/library maintainer if it comes from a package.

Example fix

// before: custom resource unmapped in DCP projection
var dcpObject = new MyCustomDcpType { ... };
// after: project to a supported DCP kind
var dcpObject = new Executable { ... }; // or Container / ContainerExec
Defensive patterns

Strategy: type-guard

Type guard

static bool HasSupportedDcpKind(object dcpObject) =>
    dcpObject is Container or Executable or ContainerExec;

Try / catch

try
{
    var kind = executor.ResourceType(resource);
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Unknown resource type"))
{
    logger.LogError(ex, "Unsupported DCP object for {Resource}; check integration versions.", resource.Name);
}

Prevention

When it happens

Trigger: DcpExecutor creates DCP objects for a resource whose DCP type is not one of Container, Executable, or ContainerExec (via GetResourceType, backing the resourceType property).

Common situations: A custom resource or new DCP object kind introduced without updating DcpExecutor's switch; version skew between Aspire.Hosting assemblies; custom IDcpObjectFactory implementations emitting unsupported types.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting/Dcp/DcpExecutor.cs:382

                (applicationName[i] is >= 'A' and <= 'Z') ||
                (applicationName[i] is >= '0' and <= '9') ||
                (applicationName[i] is '_' or '-' or '.'))
            {
                normalizedName.Append(applicationName[i]);
            }
        }

        return normalizedName.ToString();
    }

    internal static string GetResourceType<T>(T resource, IResource appModelResource) where T : CustomResource
    {
        return resource switch
        {
            Container => KnownResourceTypes.Container,
            Executable => appModelResource.GetResourceType(),
            ContainerExec => KnownResourceTypes.ContainerExec,
            _ => throw new InvalidOperationException($"Unknown resource type {resource.GetType().Name}")
        };
    }

    Task IDcpObjectFactory.UpdateWithEffectiveAddressInfo(IEnumerable<Service> services, CancellationToken cancellationToken, TimeSpan? timeout)
        => UpdateWithEffectiveAddressInfo(services, cancellationToken, timeout);

    // Watches DCP object updates via a Kubernetes watch wrapped in the supplied retry pipeline,
    // till all objects reach desired state or a timeout occurs.
    // Returns names of objects that did not reach the desired state.
    private async Task<HashSet<string>> WatchUntilDesiredStateAsync<TDcpResource>(
        IEnumerable<TDcpResource> objects,
        Func<TDcpResource, TDcpResource, bool> isInDesiredState,
        ResiliencePipeline pipeline,
        CancellationToken cancellationToken)
        where TDcpResource : CustomResource, IKubernetesStaticMetadata
    {
        var objectsByName = new Dictionary<string, TDcpResource>(StringComparer.Ordinal);
        var pending = new HashSet<string>(StringComparer.Ordinal);

View on GitHub (pinned to 25830f84bd)