dotnet/yarp · critical · InvalidOperationException
Routing Endpoint wasn't set for the current request.
Error message
Routing Endpoint wasn't set for the current request.
What it means
The `ProxyPipelineInitializerMiddleware` expects ASP.NET Core endpoint routing to have resolved an endpoint for the current request. It retrieves the endpoint via `context.GetEndpoint()`. If null, it means routing middleware (`UseRouting`) has not run, or this YARP middleware is placed in the pipeline before endpoint resolution. The proxy cannot proceed without knowing which route matched.
Source
Thrown at src/ReverseProxy/Model/ProxyPipelineInitializerMiddleware.cs:39
private readonly ILogger _logger;
private readonly RequestDelegate _next;
private readonly IOptionsMonitor<RequestTimeoutOptions> _timeoutOptions;
public ProxyPipelineInitializerMiddleware(RequestDelegate next, ILogger<ProxyPipelineInitializerMiddleware> logger, IOptionsMonitor<RequestTimeoutOptions> timeoutOptions)
{
ArgumentNullException.ThrowIfNull(logger);
ArgumentNullException.ThrowIfNull(next);
ArgumentNullException.ThrowIfNull(timeoutOptions);
_logger = logger;
_next = next;
_timeoutOptions = timeoutOptions;
}
public Task Invoke(HttpContext context)
{
var endpoint = context.GetEndpoint()
?? throw new InvalidOperationException($"Routing Endpoint wasn't set for the current request.");
var route = endpoint.Metadata.GetMetadata<RouteModel>()
?? throw new InvalidOperationException($"Routing Endpoint is missing {typeof(RouteModel).FullName} metadata.");
var cluster = route.Cluster;
// TODO: Validate on load https://github.com/dotnet/yarp/issues/797
if (cluster is null)
{
Log.NoClusterFound(_logger, route.Config.RouteId);
context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
return Task.CompletedTask;
}
EnsureRequestTimeoutPolicyIsAppliedCorrectly(context, endpoint, route);
var destinationsState = cluster.DestinationsState;
context.Features.Set<IReverseProxyFeature>(new ReverseProxyFeature
{View on GitHub (pinned to bd11867bee)
Solutions
- Ensure `app.UseRouting()` is called before `app.MapReverseProxy()` in the middleware pipeline.
- Verify `MapReverseProxy()` is called inside `app.UseEndpoints(...)` (or uses the modern minimal `app.MapReverseProxy()` which handles this internally).
- Check that no middleware between `UseRouting` and the endpoint short-circuits the request before endpoint selection.
- If using a custom middleware pipeline inside `MapReverseProxy`, ensure the proxy initializer middleware is not duplicated or misplaced.
Example fix
// before — UseRouting missing or after proxy
var app = builder.Build();
app.MapReverseProxy(); // no UseRouting — throws
app.Run();
// after — correct ordering
var app = builder.Build();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapReverseProxy();
});
app.Run(); Defensive patterns
Strategy: validation
Validate before calling
// Verify middleware ordering at startup
// Ensure UseRouting is registered before the proxy endpoints
// This is a code-structure check, not a runtime validation
/*
Required order:
app.UseRouting();
app.UseEndpoints(endpoints => { endpoints.MapReverseProxy(); });
*/ Type guard
// No type guard — this is a pipeline-configuration issue.
Try / catch
// Not applicable — this is a startup configuration error. // Fix by adding UseRouting() before the proxy endpoints.
Prevention
- Always call app.UseRouting() before app.MapReverseProxy().
- Use the standard Program.cs template from YARP documentation.
- Review middleware ordering after refactoring Program.cs.
When it happens
Trigger: `ProxyPipelineInitializerMiddleware.Invoke` is called but `context.GetEndpoint()` returns null. This happens when `UseRouting()` was not called before the proxy middleware, or the middleware was accidentally added outside the endpoint-mapped pipeline (e.g., as a bare `app.UseMiddleware<ProxyPipelineInitializerMiddleware>()`).
Common situations: A developer removes `app.UseRouting()` while refactoring, not realizing YARP depends on endpoint routing. The YARP middleware is registered before `UseRouting` in the pipeline ordering. A misconfigured custom pipeline adds the proxy middleware at the wrong position.
Related errors
- Routing Endpoint is missing {typeof(RouteModel).FullName} me
- The {typeof(IReverseProxyFeature).FullName} is missing the {
- {typeof(IReverseProxyFeature).FullName} is missing.
- The timeout was not applied for route '{route.Config.RouteId
- Configuration Filter Error: Substitution for '{lookup}' in c
AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13).
Data as JSON: /api/errors/210382a39b94825d.
Report an issue: GitHub.