{"record":{"id":"bc8a84f12badb580","repo":"microsoft/aspire","slug":"destination-must-be-an-ivalueprovider-string-or-uri-got-dest","errorCode":null,"errorMessage":"Destination must be an IValueProvider, string, or Uri. Got: {dest?.GetType().FullName ?? \"null\"}","messagePattern":"Destination must be an IValueProvider, string, or Uri\\. Got: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpConfigurationBuilder.cs","lineNumber":69,"sourceCode":"    }\n\n    /// <inheritdoc/>\n    public YarpCluster AddCluster(string clusterName, object[] destinations)\n    {\n        ArgumentNullException.ThrowIfNull(clusterName);\n        ArgumentNullException.ThrowIfNull(destinations);\n\n        if (destinations.Length == 0)\n        {\n            throw new ArgumentException(\"At least one destination must be provided.\", nameof(destinations));\n        }\n\n        // Validate that each destination is a supported type\n        foreach (var dest in destinations)\n        {\n            if (dest is not (IValueProvider or string or Uri))\n            {\n                throw new ArgumentException(\n                    $\"Destination must be an IValueProvider, string, or Uri. Got: {dest?.GetType().FullName ?? \"null\"}\",\n                    nameof(destinations));\n            }\n        }\n\n        var destination = new YarpCluster(clusterName, destinations);\n        _parent.Resource.Clusters.Add(destination);\n        return destination;\n    }\n\n    internal YarpRoute AddRoute(string path, object destination)\n    {\n        var cluster = AddCluster(YarpConfigurationBuilderHelpers.CreateSyntheticClusterName(path, destination.ToString()!), [destination]);\n        return AddRoute(path, cluster);\n    }\n}\n","sourceCodeStart":51,"sourceCodeEnd":86,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpConfigurationBuilder.cs#L51-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert each destination to a supported type: a literal string URL, a Uri, or an IValueProvider (e.g. endpoint reference / parameter expression).","For a resource, pass its endpoint reference (IResourceBuilder<>.GetEndpoint(...)) which implements IValueProvider, not the resource object.","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."],"exampleFix":"// before\nbuilder.AddCluster(\"apis\", myProject.Resource); // resource, not a destination\n// after\nbuilder.AddCluster(\"apis\", myProject.GetEndpoint(\"https\"));","handlingStrategy":"type-guard","validationCode":"foreach (var dest in destinations)\n{\n    if (dest is not (IValueProvider or string or Uri))\n    {\n        throw new InvalidOperationException($\"Destination '{dest?.GetType().FullName ?? \"null\"}' must be IValueProvider, string, or Uri.\");\n    }\n}","typeGuard":"bool IsValidDestination(object? dest) => dest is IValueProvider or string or Uri;","tryCatchPattern":"catch (ArgumentException ex) when (ex.ParamName == \"destinations\" && ex.Message.StartsWith(\"Destination must be\")) { /* inspect dest?.GetType().FullName from message */ }","preventionTips":["Pass endpoint references (GetEndpoint(...)) or URL strings, never resource objects.","Keep destination arrays strongly typed (string[]/Uri[]/IValueProvider[]) instead of object[].","Check for null array elements from dynamic configuration before calling AddCluster."],"tags":["yarp","cluster","type-mismatch","destination"],"backgroundTag":"type-mismatch","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"}