dotnet/yarp · error · ArgumentException
'key' cannot be null or empty.
Error message
'key' cannot be null or empty.
What it means
Thrown by the QueryParameterRemoveTransform constructor when `key` is null or empty. The transform removes a named query parameter; without a name there is nothing to remove, so it is rejected as ArgumentException on `key`.
Source
Thrown at src/ReverseProxy/Transforms/QueryParameterRemoveTransform.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>
/// A request transform that removes the given query parameter.
/// </summary>
public class QueryParameterRemoveTransform : RequestTransform
{
public QueryParameterRemoveTransform(string key)
{
if (string.IsNullOrEmpty(key))
{
throw new ArgumentException($"'{nameof(key)}' cannot be null or empty.", nameof(key));
}
Key = key;
}
internal string Key { get; }
/// <inheritdoc/>
public override ValueTask ApplyAsync(RequestTransformContext context)
{
ArgumentNullException.ThrowIfNull(context);
context.Query.Collection.Remove(Key);
return default;
}
}
View on GitHub (pinned to bd11867bee)
Solutions
- Provide a non-empty query-parameter name to remove.
- Validate the key before constructing if sourced from input.
- Fix the transform config to include the key.
Example fix
// before
new QueryParameterRemoveTransform("");
// after
new QueryParameterRemoveTransform("tracking"); Defensive patterns
Strategy: validation
Validate before calling
ArgumentException.ThrowIfNullOrEmpty(key);
Type guard
static bool IsValidQueryKey(string? key) => !string.IsNullOrEmpty(key);
Prevention
- Always specify the query parameter name to remove.
- Validate config keys for query-remove transforms.
- Use ArgumentException.ThrowIfNullOrEmpty before constructing.
When it happens
Trigger: Constructing `new QueryParameterRemoveTransform(key)` with `key` null/empty/whitespace, or via transform config that omits the query parameter name to remove.
Common situations: Config sets a query-remove transform with no key. Programmatic construction from input that yielded an empty key.
Related errors
- '{nameof(key)}' cannot be null or empty.
- '{nameof(routeValueKey)}' cannot be null or empty.
- '{nameof(key)}' cannot be null or empty.
- 'key' cannot be null or empty.
- '{nameof(fromMethod)}' cannot be null or empty.
AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13).
Data as JSON: /api/errors/355fead469272056.
Report an issue: GitHub.