microsoft/aspire · error · ArgumentException

Destination must be an IValueProvider, string, or Uri. Got

Error message

Destination must be an IValueProvider, string, or Uri. Got: {dest?.GetType().FullName ?? "null"}

What it means

Thrown by AddCluster when a destination item is not an IValueProvider, string, or Uri — the only destination types the YARP builder supports. The exception message reports the offending type's full name (or "null"), helping identify which element in the params array is wrong.

Solutions

  1. Convert each destination to a supported type: a literal string URL, a Uri, or an IValueProvider (e.g. endpoint reference / parameter expression).
  2. For a resource, pass its endpoint reference (IResourceBuilder<>.GetEndpoint(...)) which implements IValueProvider, not the resource object.
  3. Log or inspect dest?.GetType().FullName from the message to find which array element is the wrong type and fix the producer of that array.

Example fix

// before
builder.AddCluster("apis", myProject.Resource); // resource, not a destination
// after
builder.AddCluster("apis", myProject.GetEndpoint("https"));
Defensive patterns

Strategy: type-guard

Validate before calling

foreach (var dest in destinations)
{
    if (dest is not (IValueProvider or string or Uri))
    {
        throw new InvalidOperationException($"Destination '{dest?.GetType().FullName ?? "null"}' must be IValueProvider, string, or Uri.");
    }
}

Type guard

bool IsValidDestination(object? dest) => dest is IValueProvider or string or Uri;

Try / catch

catch (ArgumentException ex) when (ex.ParamName == "destinations" && ex.Message.StartsWith("Destination must be")) { /* inspect dest?.GetType().FullName from message */ }

Prevention

When it happens

Trigger: Calling builder.AddCluster("name", someEndpointObject) where an element is e.g. a HostString, an int port, a custom class, a ReferenceExpression of the wrong shape, or a null element that isn't IValueProvider/string/Uri.

Common situations: Passing a connection-string object or a DCP endpoint type directly; using var arrays typed object[] with mixed junk; passing a container resource itself instead of its endpoint reference; accidentally passing null in the array.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpConfigurationBuilder.cs:69

    }

    /// <inheritdoc/>
    public YarpCluster AddCluster(string clusterName, object[] destinations)
    {
        ArgumentNullException.ThrowIfNull(clusterName);
        ArgumentNullException.ThrowIfNull(destinations);

        if (destinations.Length == 0)
        {
            throw new ArgumentException("At least one destination must be provided.", nameof(destinations));
        }

        // Validate that each destination is a supported type
        foreach (var dest in destinations)
        {
            if (dest is not (IValueProvider or string or Uri))
            {
                throw new ArgumentException(
                    $"Destination must be an IValueProvider, string, or Uri. Got: {dest?.GetType().FullName ?? "null"}",
                    nameof(destinations));
            }
        }

        var destination = new YarpCluster(clusterName, destinations);
        _parent.Resource.Clusters.Add(destination);
        return destination;
    }

    internal YarpRoute AddRoute(string path, object destination)
    {
        var cluster = AddCluster(YarpConfigurationBuilderHelpers.CreateSyntheticClusterName(path, destination.ToString()!), [destination]);
        return AddRoute(path, cluster);
    }
}

View on GitHub (pinned to 25830f84bd)