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 QueryParameterFromStaticTransform constructor when `key` is null or empty. The transform adds a static value under `key`; a blank query-parameter name is invalid, so it is rejected as ArgumentException before the base class is reached.

Source

Thrown at src/ReverseProxy/Transforms/QueryParameterFromStaticTransform.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 QueryParameterFromStaticTransform : QueryParameterTransform
{
    public QueryParameterFromStaticTransform(QueryStringTransformMode mode, string key, string value)
        : base(mode, key)
    {
        if (string.IsNullOrEmpty(key))
        {
            throw new ArgumentException($"'{nameof(key)}' cannot be null or empty.", nameof(key));
        }

        ArgumentNullException.ThrowIfNull(value);

        Value = value;
    }

    internal string Value { get; }

    /// <inheritdoc/>
    protected override string GetValue(RequestTransformContext context)
    {
        return Value;
    }
}

View on GitHub (pinned to bd11867bee)

Solutions

  1. Provide a non-empty query-parameter name for `key`.
  2. Guard the value before constructing if it comes from input.
  3. Complete the transform config with both key and value.

Example fix

// before
new QueryParameterFromStaticTransform(QueryStringTransformMode.Set, "", "v1");
// after
new QueryParameterFromStaticTransform(QueryStringTransformMode.Set, "ver", "v1");
Defensive patterns

Strategy: validation

Validate before calling

ArgumentException.ThrowIfNullOrEmpty(key);
ArgumentNullException.ThrowIfNull(value);

Type guard

static bool IsValidQueryKey(string? key) => !string.IsNullOrEmpty(key);

Prevention

When it happens

Trigger: Constructing `new QueryParameterFromStaticTransform(mode, key, value)` with `key` null/empty, or transform config that omits the query key while supplying a value.

Common situations: Config sets a static query transform with a value but no key. Programmatic construction from input that yielded an empty key.

Related errors


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