dotnet/yarp · error · ArgumentException
'{nameof(key)}' cannot be null or empty.
Error message
'{nameof(key)}' cannot be null or empty. What it means
Thrown by the QueryParameterRouteTransform constructor when `key` is null or empty. The `key` is the query-parameter name to set/append; the base QueryParameterTransform also validates it, but this subclass re-checks to give an explicit ArgumentException before delegating to the base. A blank key produces an invalid query string.
Source
Thrown at src/ReverseProxy/Transforms/QueryParameterFromRouteTransform.cs:15
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
namespace Yarp.ReverseProxy.Transforms;
public class QueryParameterRouteTransform : QueryParameterTransform
{
public QueryParameterRouteTransform(QueryStringTransformMode mode, string key, string routeValueKey)
: base(mode, key)
{
if (string.IsNullOrEmpty(key))
{
throw new ArgumentException($"'{nameof(key)}' cannot be null or empty.", nameof(key));
}
if (string.IsNullOrEmpty(routeValueKey))
{
throw new ArgumentException($"'{nameof(routeValueKey)}' cannot be null or empty.", nameof(routeValueKey));
}
RouteValueKey = routeValueKey;
}
internal string RouteValueKey { get; }
/// <inheritdoc/>
protected override string? GetValue(RequestTransformContext context)
{
var routeValues = context.HttpContext.Request.RouteValues;
if (!routeValues.TryGetValue(RouteValueKey, out var value))
{View on GitHub (pinned to bd11867bee)
Solutions
- Provide a non-empty query-parameter name for `key`.
- If sourced from config, validate the key is present before constructing.
- Ensure the transform config block has all required keys.
Example fix
// before new QueryParameterRouteTransform(QueryStringTransformMode.Append, "", "userId"); // after new QueryParameterRouteTransform(QueryStringTransformMode.Append, "uid", "userId");
Defensive patterns
Strategy: validation
Validate before calling
ArgumentException.ThrowIfNullOrEmpty(key);
Type guard
static bool IsValidQueryKey(string? key) => !string.IsNullOrEmpty(key);
Prevention
- Require a non-empty query key in config binding.
- Use ArgumentException.ThrowIfNullOrEmpty before constructing.
- Add startup validation for query-transform config.
When it happens
Trigger: Constructing `new QueryParameterRouteTransform(mode, key, routeValueKey)` with `key` null/empty, or via transform config that omits the query key.
Common situations: Config sets `Set`/`Append` query transform from route but leaves `key` blank. Programmatically building the transform from a config value that defaulted to empty.
Related errors
- '{nameof(routeValueKey)}' cannot be null or empty.
- '{nameof(key)}' cannot be null or empty.
- '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/1e7f01b5b3404feb.
Report an issue: GitHub.