{"record":{"id":"6c93dfe20f048c51","repo":"microsoft/aspire","slug":"at-least-one-destination-must-be-provided","errorCode":null,"errorMessage":"At least one destination must be provided.","messagePattern":"At least one destination must be provided\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpConfigurationBuilder.cs","lineNumber":61,"sourceCode":"\n    /// <inheritdoc/>\n    public YarpCluster AddCluster(IResourceBuilder<ExternalServiceResource> externalService)\n    {\n        var destination = new YarpCluster(externalService.Resource);\n        _parent.Resource.Clusters.Add(destination);\n        _parent.WithReference(externalService);\n        return destination;\n    }\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","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpConfigurationBuilder.cs#L43-L79","documentation":"Thrown by IYarpConfigurationBuilder.AddCluster when the destinations params array is empty. A YARP cluster must forward to at least one destination; an empty set would produce a cluster that can never serve traffic, so the builder rejects it at configuration time.","triggerScenarios":"Calling builder.AddCluster(\"cluster-name\") with no destination arguments, or AddCluster(name, destinations) with a zero-length array/collection.","commonSituations":"Building destinations dynamically from configuration or environment where the list came back empty; conditional code that skips the only WithDestination call; refactoring that accidentally dropped destinations.","solutions":["Pass at least one destination, e.g. builder.AddCluster(\"backend\", \"http://backend:8080\") or a reference to a project/container resource.","If destinations are dynamic, check the collection's Length/Count > 0 before calling AddCluster and handle the empty case explicitly.","Inspect the code path producing the destinations array to see why it yielded no entries (config key missing, empty env var, filtered list)."],"exampleFix":"// before\nvar cluster = builder.AddCluster(\"apis\", destinations);\n// after\nif (destinations.Length == 0)\n{\n    throw new InvalidOperationException(\"No destinations configured for cluster 'apis'.\");\n}\nvar cluster = builder.AddCluster(\"apis\", destinations);","handlingStrategy":"validation","validationCode":"if (destinations is null || destinations.Length == 0)\n{\n    throw new InvalidOperationException(\"AddCluster requires at least one destination.\");\n}","typeGuard":null,"tryCatchPattern":"catch (ArgumentException ex) when (ex.ParamName == \"destinations\") { /* fall back to default destination or fail app model build with clear message */ }","preventionTips":["When building destinations dynamically, assert the list is non-empty right before AddCluster.","Always register at least one backing resource endpoint per cluster.","Guard config-driven destination lists against missing keys yielding empty arrays."],"tags":["yarp","cluster","empty-argument","validation"],"backgroundTag":"empty-required-field","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"}