dotnet/yarp · error · ArgumentException
'headerName' cannot be null or empty.
Error message
'headerName' cannot be null or empty.
What it means
ResponseHeaderRemoveTransform's constructor throws ArgumentException when headerName is null or empty. The transform removes a named response header, so a concrete name is required. The constructor also accepts a ResponseCondition (Always/Success/Failure) controlling when removal applies.
Source
Thrown at src/ReverseProxy/Transforms/ResponseHeaderRemoveTransform.cs:18
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Threading.Tasks;
namespace Yarp.ReverseProxy.Transforms;
/// <summary>
/// Removes a response header.
/// </summary>
public class ResponseHeaderRemoveTransform : ResponseTransform
{
public ResponseHeaderRemoveTransform(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(ResponseTransformContext context)
{
ArgumentNullException.ThrowIfNull(context);
if (Condition == ResponseCondition.Always
|| Success(context) == (Condition == ResponseCondition.Success))View on GitHub (pinned to bd11867bee)
Solutions
- Provide a real response header name, e.g. "Server".
- Populate the config ResponseHeaderRemove value.
- Filter empty strings from dynamically generated lists before constructing.
Example fix
// before
{ "ResponseHeaderRemove": "" }
// after
{ "ResponseHeaderRemove": "Server" } Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(headerName))
throw new InvalidOperationException("A response header name is required to remove.");
var t = new ResponseHeaderRemoveTransform(headerName, condition); Type guard
static bool IsValidHeaderName(string? name)
=> !string.IsNullOrWhiteSpace(name); Prevention
- Filter empty entries from dynamic header-name lists before constructing.
- Validate config ResponseHeaderRemove values are non-empty.
- Prefer context.AddResponseHeaderRemove from validated config.
When it happens
Trigger: Constructing `new ResponseHeaderRemoveTransform(headerName, condition)` with a null/empty headerName. Reached via config when a 'ResponseHeaderRemove' value is empty, or programmatically.
Common situations: Config `{ "ResponseHeaderRemove": "" }`; a programmatic transform with an uninitialised name variable; dynamic header list yielding an empty entry.
Related errors
- 'headerName' cannot be null or empty.
- 'headerName' cannot be null or empty.
- 'headerName' cannot be null or empty.
- 'headerName' cannot be null or empty.
- 'headerName' cannot be null or empty.
AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13).
Data as JSON: /api/errors/a39ddb12e8b58664.
Report an issue: GitHub.