{"record":{"id":"a69bf4eae1bc24c0","repo":"dotnet/yarp","slug":"nameof-frommethod-cannot-be-null-or-empty","errorCode":null,"errorMessage":"'{nameof(fromMethod)}' cannot be null or empty.","messagePattern":"'(.+?)' cannot be null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ReverseProxy/Transforms/HttpMethodChangeTransform.cs","lineNumber":25,"sourceCode":"using Microsoft.AspNetCore.Http;\n\nnamespace Yarp.ReverseProxy.Transforms;\n\n/// <summary>\n/// Replaces the HTTP method if it matches.\n/// </summary>\npublic class HttpMethodChangeTransform : RequestTransform\n{\n    /// <summary>\n    /// Creates a new transform.\n    /// </summary>\n    /// <param name=\"fromMethod\">The method to match.</param>\n    /// <param name=\"toMethod\">The method to it change to.</param>\n    public HttpMethodChangeTransform(string fromMethod, string toMethod)\n    {\n        if (string.IsNullOrEmpty(fromMethod))\n        {\n            throw new ArgumentException($\"'{nameof(fromMethod)}' cannot be null or empty.\", nameof(fromMethod));\n        }\n\n        if (string.IsNullOrEmpty(toMethod))\n        {\n            throw new ArgumentException($\"'{nameof(toMethod)}' cannot be null or empty.\", nameof(toMethod));\n        }\n\n        FromMethod = GetCanonicalizedValue(fromMethod);\n        ToMethod = GetCanonicalizedValue(toMethod);\n    }\n\n    internal HttpMethod FromMethod { get; }\n\n    internal HttpMethod ToMethod { get; }\n\n    /// <inheritdoc/>\n    public override ValueTask ApplyAsync(RequestTransformContext context)\n    {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Transforms/HttpMethodChangeTransform.cs#L7-L43","documentation":"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.","triggerScenarios":"Constructing `new HttpMethodChangeTransform(fromMethod, toMethod)` with `fromMethod` null/empty/whitespace, or via transform config that omits or blanks the from-method.","commonSituations":"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.","solutions":["Provide a non-empty HTTP method for `fromMethod` (e.g. \"POST\", \"GET\").","If building from input, guard with `string.IsNullOrEmpty` before constructing.","Fix the transform config to include a valid from-method key."],"exampleFix":"// before\nnew HttpMethodChangeTransform(\"\", \"PUT\");\n// after\nnew HttpMethodChangeTransform(\"POST\", \"PUT\");","handlingStrategy":"validation","validationCode":"ArgumentException.ThrowIfNullOrEmpty(fromMethod);","typeGuard":"static bool IsValidHttpMethod(string? m) =>\n    !string.IsNullOrEmpty(m) && m.All(c => c >= 'A' && c <= 'Z' || c == '-');","tryCatchPattern":null,"preventionTips":["Use ArgumentException.ThrowIfNullOrEmpty before constructing.","Source from-method and to-method from validated config.","Standardize on uppercase canonical method names."],"tags":["transforms","http-method","argument-validation","yarp"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}