dotnet/yarp · error · InvalidOperationException

{typeof(IReverseProxyFeature).FullName} is missing.

Error message

{typeof(IReverseProxyFeature).FullName} is missing.

What it means

`GetReverseProxyFeature()` retrieves the `IReverseProxyFeature` from `HttpContext.Features`. If the feature is not set, the request is not being processed through the YARP proxy pipeline (or the middleware hasn't run yet). This extension method is intended for use inside transforms, direct forwarding handlers, or middleware that runs within the proxy pipeline where the feature is always populated.

Source

Thrown at src/ReverseProxy/Model/HttpContextFeaturesExtensions.cs:33

    /// <summary>
    /// Retrieves the <see cref="RouteModel"/> instance associated with the current request.
    /// </summary>
    public static RouteModel GetRouteModel(this HttpContext context)
    {
        var proxyFeature = context.GetReverseProxyFeature();

        var route = proxyFeature.Route
            ?? throw new InvalidOperationException($"The {typeof(IReverseProxyFeature).FullName} is missing the {typeof(RouteModel).FullName}.");

        return route;
    }

    /// <summary>
    /// Retrieves the <see cref="IReverseProxyFeature"/> instance associated with the current request.
    /// </summary>
    public static IReverseProxyFeature GetReverseProxyFeature(this HttpContext context)
    {
        return context.Features.Get<IReverseProxyFeature>() ?? throw new InvalidOperationException($"{typeof(IReverseProxyFeature).FullName} is missing.");
    }

    /// <summary>
    /// Retrieves the <see cref="IForwarderErrorFeature"/> instance associated with the current request, if any.
    /// </summary>
    public static IForwarderErrorFeature? GetForwarderErrorFeature(this HttpContext context)
    {
        return context.Features.Get<IForwarderErrorFeature>();
    }

    // Compare to ProxyPipelineInitializerMiddleware
    /// <summary>
    /// Replaces the assigned cluster and destinations in <see cref="IReverseProxyFeature"/> with the new <see cref="ClusterState"/>,
    /// causing the request to be sent to the new cluster instead.
    /// </summary>
    public static void ReassignProxyRequest(this HttpContext context, ClusterState cluster)
    {
        var oldFeature = context.GetReverseProxyFeature();

View on GitHub (pinned to bd11867bee)

Solutions

  1. Only call `GetReverseProxyFeature()` from code that executes within the YARP proxy pipeline — inside transforms, inside `MapReverseProxy` pipeline branches, or in middleware registered via `app.MapReverseProxy(pipeline => pipeline.Use(...))`.
  2. If you need proxy feature data outside the pipeline, pass it through a different mechanism (e.g., items bag set earlier in the pipeline).
  3. Guard with a null check: `context.Features.Get<IReverseProxyFeature>()` and handle the null case gracefully if the code may run outside the pipeline.
  4. Verify the route is actually mapped through `MapReverseProxy()` or `MapForwarder()`, not through standard MVC routing.

Example fix

// before — called outside the proxy pipeline, throws
app.Use(async (context, next) =>
{
    var feature = context.GetReverseProxyFeature(); // throws if not in proxy pipeline
    await next();
});
app.UseRouting();
app.MapReverseProxy();
// after — guard or move inside the pipeline
app.MapReverseProxy(pipeline =>
{
    pipeline.Use(async (context, next) =>
    {
        var feature = context.GetReverseProxyFeature(); // safe: inside pipeline
        await next();
    });
    pipeline.RunProxy();
});
Defensive patterns

Strategy: validation

Validate before calling

// Safe access pattern
var feature = context.Features.Get<IReverseProxyFeature>();
if (feature is null)
{
    // Request is not being handled by the proxy pipeline
    context.Response.StatusCode = 500;
    return;
}

Type guard

static IReverseProxyFeature? TryGetProxyFeature(HttpContext context)
    => context.Features.Get<IReverseProxyFeature>();

Try / catch

// Not recommended to catch — use Features.Get<IReverseProxyFeature>() with null check instead.

Prevention

When it happens

Trigger: `GetReverseProxyFeature()` is called in middleware or a controller that runs outside the YARP proxy pipeline — before `ProxyPipelineInitializerMiddleware.Invoke` has set the feature at line 56. The `context.Features.Get<IReverseProxyFeature>()` returns null and the throw fires.

Common situations: A developer calls `context.GetReverseProxyFeature()` in a regular MVC controller or Razor Page handler that is not part of a proxied route. Someone calls it in middleware registered before `MapReverseProxy()`. A direct-forwarding scenario (`MapForwarder`) calls it before the pipeline runs.

Related errors


AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13). Data as JSON: /api/errors/1e9f08daac32d3ce. Report an issue: GitHub.