dotnet/yarp · error · ArgumentException

'{nameof(fromMethod)}' cannot be null or empty.

Error message

'{nameof(fromMethod)}' cannot be null or empty.

What it means

Thrown by the HttpMethodChangeTransform constructor when `fromMethod` is null or empty. The transform rewrites requests whose method matches `fromMethod` to `toMethod`, so a blank source method makes the transform a no-op and is rejected as ArgumentException on the parameter.

Source

Thrown at src/ReverseProxy/Transforms/HttpMethodChangeTransform.cs:25

using Microsoft.AspNetCore.Http;

namespace Yarp.ReverseProxy.Transforms;

/// <summary>
/// Replaces the HTTP method if it matches.
/// </summary>
public class HttpMethodChangeTransform : RequestTransform
{
    /// <summary>
    /// Creates a new transform.
    /// </summary>
    /// <param name="fromMethod">The method to match.</param>
    /// <param name="toMethod">The method to it change to.</param>
    public HttpMethodChangeTransform(string fromMethod, string toMethod)
    {
        if (string.IsNullOrEmpty(fromMethod))
        {
            throw new ArgumentException($"'{nameof(fromMethod)}' cannot be null or empty.", nameof(fromMethod));
        }

        if (string.IsNullOrEmpty(toMethod))
        {
            throw new ArgumentException($"'{nameof(toMethod)}' cannot be null or empty.", nameof(toMethod));
        }

        FromMethod = GetCanonicalizedValue(fromMethod);
        ToMethod = GetCanonicalizedValue(toMethod);
    }

    internal HttpMethod FromMethod { get; }

    internal HttpMethod ToMethod { get; }

    /// <inheritdoc/>
    public override ValueTask ApplyAsync(RequestTransformContext context)
    {

View on GitHub (pinned to bd11867bee)

Solutions

  1. Provide a non-empty HTTP method for `fromMethod` (e.g. "POST", "GET").
  2. If building from input, guard with `string.IsNullOrEmpty` before constructing.
  3. Fix the transform config to include a valid from-method key.

Example fix

// before
new HttpMethodChangeTransform("", "PUT");
// after
new HttpMethodChangeTransform("POST", "PUT");
Defensive patterns

Strategy: validation

Validate before calling

ArgumentException.ThrowIfNullOrEmpty(fromMethod);

Type guard

static bool IsValidHttpMethod(string? m) =>
    !string.IsNullOrEmpty(m) && m.All(c => c >= 'A' && c <= 'Z' || c == '-');

Prevention

When it happens

Trigger: Constructing `new HttpMethodChangeTransform(fromMethod, toMethod)` with `fromMethod` null/empty/whitespace, or via transform config that omits or blanks the from-method.

Common situations: Config binds `from`/`to` keys but `from` is missing or set to empty. Programmatic transform built from request data that yielded an empty method string.

Related errors


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