{"record":{"id":"c67b6b59ff446767","repo":"dotnet/yarp","slug":"typeof-ihttpsysrequestdelegationfeature-fullname-c67b6b","errorCode":null,"errorMessage":"{typeof(IHttpSysRequestDelegationFeature).FullName} is missing.","messagePattern":"(.+?) is missing\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ReverseProxy/Delegation/HttpSysDelegator.cs","lineNumber":63,"sourceCode":"    {\n        if (_serverDelegationFeature is not null)\n        {\n            var key = new QueueKey(queueName, urlPrefix);\n            if (_queues.TryGetValue(key, out var queueWeakRef) && queueWeakRef.TryGetTarget(out var queue))\n            {\n                var detachedQueueState = queue.Detach();\n                Log.QueueReset(_logger, queueName, urlPrefix, detachedQueueState);\n            }\n        }\n    }\n\n    public void DelegateRequest(HttpContext context, DestinationState destination)\n    {\n        ArgumentNullException.ThrowIfNull(context);\n        ArgumentNullException.ThrowIfNull(destination);\n\n        var requestDelegationFeature = context.Features.Get<IHttpSysRequestDelegationFeature>()\n                    ?? throw new InvalidOperationException($\"{typeof(IHttpSysRequestDelegationFeature).FullName} is missing.\");\n\n        if (!requestDelegationFeature.CanDelegate)\n        {\n            throw new InvalidOperationException(\n                \"Current request can't be delegated. Either the request body has started to be read or the response has started to be sent.\");\n        }\n\n        if (_serverDelegationFeature is null || !_queuesPerDestination.TryGetValue(destination, out var queue))\n        {\n            Log.QueueNotFound(_logger, destination);\n            context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;\n            context.Features.Set<IForwarderErrorFeature>(new ForwarderErrorFeature(ForwarderError.NoAvailableDestinations, ex: null));\n            return;\n        }\n\n        Delegate(context, destination, _serverDelegationFeature, requestDelegationFeature, queue, _logger, shouldRetry: true);\n\n        static void Delegate(","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Delegation/HttpSysDelegator.cs#L45-L81","documentation":"Thrown by HttpSysDelegator.DelegateRequest when the per-request IHttpSysRequestDelegationFeature is not present on the HttpContext features. This feature is supplied by the Http.sys server per connection; its absence means the request is not running on Http.sys or the feature was stripped. The delegator cannot forward the request to an Http.sys queue without it.","triggerScenarios":"DelegateRequest is invoked for a request that is not handled by the Http.sys server, or where the delegation feature was not initialized for that connection. This can happen if delegation middleware runs for a non-Http.sys pipeline.","commonSituations":"Mixing Kestrel-hosted requests with HttpSysDelegator. A misconfigured pipeline where delegation logic runs for requests not backed by Http.sys. Feature removed by another middleware.","solutions":["Ensure the application is hosted on Http.sys (UseHttpSys) so IHttpSysRequestDelegationFeature is populated.","Confirm UseHttpSysDelegation is only in the pipeline when Http.sys is the server.","Add a server-feature guard before calling DelegateRequest to skip non-Http.sys requests."],"exampleFix":"// before\n_delegator.DelegateRequest(context, destination); // throws if feature missing\n// after\nif (context.Features.Get<IHttpSysRequestDelegationFeature>() is { } feat && feat.CanDelegate)\n{\n    _delegator.DelegateRequest(context, destination);\n}\nelse\n{\n    // fall back to normal proxying or 503\n}","handlingStrategy":"type-guard","validationCode":"var feat = context.Features.Get<IHttpSysRequestDelegationFeature>();\nif (feat is null)\n{\n    context.Response.StatusCode = 503;\n    return;\n}","typeGuard":"static bool HasRequestDelegationFeature(HttpContext ctx) =>\n    ctx.Features.Get<IHttpSysRequestDelegationFeature>() is not null;","tryCatchPattern":"try { _delegator.DelegateRequest(context, destination); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"is missing\"))\n{ context.Response.StatusCode = 503; await context.Response.WriteAsync(\"Delegation unavailable\"); }","preventionTips":["Check IHttpSysRequestDelegationFeature before delegating.","Run delegation logic only within an Http.sys-hosted pipeline.","Provide a fallback (503 or normal proxy) when the feature is absent."],"tags":["httpsys","delegation","request-features","runtime"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}