dotnet/yarp · error · ArgumentException

'headerName' cannot be null or empty.

Error message

'headerName' cannot be null or empty.

What it means

ResponseTrailerRemoveTransform's constructor throws ArgumentException when headerName is null or empty. The transform removes a named response trailer (trailing headers in HTTP/2), so a concrete name is required. Like the response-header variant it takes a ResponseCondition.

Source

Thrown at src/ReverseProxy/Transforms/ResponseTrailerRemoveTransform.cs:20

// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features;

namespace Yarp.ReverseProxy.Transforms;

/// <summary>
/// Removes a response trailer.
/// </summary>
public class ResponseTrailerRemoveTransform : ResponseTrailersTransform
{
    public ResponseTrailerRemoveTransform(string headerName, ResponseCondition condition)
    {
        if (string.IsNullOrEmpty(headerName))
        {
            throw new ArgumentException($"'{nameof(headerName)}' cannot be null or empty.", nameof(headerName));
        }

        HeaderName = headerName;
        Condition = condition;
    }

    internal string HeaderName { get; }

    internal ResponseCondition Condition { get; }

    // Assumes the response status code has been set on the HttpContext already.
    /// <inheritdoc/>
    public override ValueTask ApplyAsync(ResponseTrailersTransformContext context)
    {
        ArgumentNullException.ThrowIfNull(context);

        Debug.Assert(context.ProxyResponse is not null);

View on GitHub (pinned to bd11867bee)

Solutions

  1. Supply a real trailer name, e.g. "X-Grpc-Status".
  2. Populate the config ResponseTrailerRemove value.
  3. Filter empty entries from dynamic lists before constructing.

Example fix

// before
{ "ResponseTrailerRemove": "" }
// after
{ "ResponseTrailerRemove": "X-Grpc-Status" }
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(headerName))
    throw new InvalidOperationException("A trailer name is required to remove.");
var t = new ResponseTrailerRemoveTransform(headerName, condition);

Type guard

static bool IsValidHeaderName(string? name)
    => !string.IsNullOrWhiteSpace(name);

Prevention

When it happens

Trigger: Constructing `new ResponseTrailerRemoveTransform(headerName, condition)` with a null/empty headerName. Via config when the 'ResponseTrailerRemove' value is empty, or programmatically.

Common situations: Config `{ "ResponseTrailerRemove": "" }`; a programmatic transform with an uninitialised name; a dynamic trailer-name list containing an empty entry.

Related errors


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