dotnet/yarp · error · InvalidOperationException
The IReverseProxyFeature Destinations collection was not set
Error message
The IReverseProxyFeature Destinations collection was not set.
What it means
Thrown by HttpSysDelegatorMiddleware.Invoke when IReverseProxyFeature.AvailableDestinations is null. The middleware expects an earlier pipeline stage (load balancing / proxy feature population) to have set the available destinations collection. A null value indicates the proxy feature was not initialized correctly for this request.
Source
Thrown at src/ReverseProxy/Delegation/HttpSysDelegatorMiddleware.cs:43
IRandomFactory randomFactory)
{
ArgumentNullException.ThrowIfNull(next);
ArgumentNullException.ThrowIfNull(logger);
ArgumentNullException.ThrowIfNull(delegator);
ArgumentNullException.ThrowIfNull(randomFactory);
_next = next;
_logger = logger;
_delegator = delegator;
_randomFactory = randomFactory;
}
public Task Invoke(HttpContext context)
{
ArgumentNullException.ThrowIfNull(context);
var reverseProxyFeature = context.GetReverseProxyFeature();
var destinations = reverseProxyFeature.AvailableDestinations
?? throw new InvalidOperationException($"The {nameof(IReverseProxyFeature)} Destinations collection was not set.");
var cluster = reverseProxyFeature.Cluster
?? throw new InvalidOperationException($"The {nameof(IReverseProxyFeature)} Cluster was not set.");
if (destinations.Any())
{
// This logic mimics behavior in ForwarderMiddleware, except we save the chosen destination back
// to the proxy feature to ensure a delegation destination doesn't slip past this middleware.
var destination = destinations[0];
if (destinations.Count > 1)
{
var random = _randomFactory.CreateRandomInstance();
Log.MultipleDestinationsAvailable(_logger, reverseProxyFeature.Cluster.Config.ClusterId);
destination = destinations[random.Next(destinations.Count)];
reverseProxyFeature.AvailableDestinations = destination;
}
if (destination.ShouldUseHttpSysDelegation())
{View on GitHub (pinned to bd11867bee)
Solutions
- Ensure UseHttpSysDelegation is placed after load balancing and the proxy feature-populating middleware.
- Do not mutate or null-out IReverseProxyFeature.AvailableDestinations in custom middleware.
- Verify the route matched has a cluster with destinations configured.
Example fix
// before — wrong order
app.MapReverseProxy(p =>
{
p.UseHttpSysDelegation(); // runs before destinations set
p.UseLoadBalancing();
});
// after
app.MapReverseProxy(p =>
{
p.UseLoadBalancing();
p.UseHttpSysDelegation();
}); Defensive patterns
Strategy: validation
Validate before calling
var feature = context.GetReverseProxyFeature();
if (feature.AvailableDestinations is null)
{
context.Response.StatusCode = 503;
return;
} Type guard
static bool HasDestinations(HttpContext ctx) =>
ctx.GetReverseProxyFeature().AvailableDestinations is not null; Try / catch
try { await _next(context); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Destinations collection was not set"))
{ context.Response.StatusCode = 503; } Prevention
- Order middleware: load balancing and feature population before delegation.
- Never null out AvailableDestinations in custom middleware.
- Test the pipeline end-to-end at startup.
When it happens
Trigger: The delegation middleware runs before the proxy has populated AvailableDestinations on the IReverseProxyFeature, or the feature itself was not attached to the context. Typically a middleware-ordering or pipeline-construction error.
Common situations: Placing UseHttpSysDelegation before UseLoadBalancing or before the proxy feature is set. Custom middleware clearing the feature. Misconfigured MapReverseProxy pipeline ordering.
Related errors
- The IReverseProxyFeature Cluster was not set.
- The IReverseProxyFeature Destinations collection was not set
- The request cannot be forwarded, the response has already st
- {typeof(IHttpSysRequestDelegationFeature).FullName} is not a
- {typeof(IHttpSysRequestDelegationFeature).FullName} is missi
AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13).
Data as JSON: /api/errors/cc03db5958e66685.
Report an issue: GitHub.