{"record":{"id":"fa229729db431fa6","repo":"dotnet/yarp","slug":"nameof-tomethod-cannot-be-null-or-empty","errorCode":null,"errorMessage":"'{nameof(toMethod)}' 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":30,"sourceCode":"/// 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    {\n        if (FromMethod.Equals(context.ProxyRequest.Method))\n        {\n            context.ProxyRequest.Method = ToMethod;\n        }\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Transforms/HttpMethodChangeTransform.cs#L12-L48","documentation":"Thrown by the HttpMethodChangeTransform constructor when `toMethod` is null or empty. The target method is what requests are rewritten to, so a blank value is rejected as ArgumentException. Distinct from the `fromMethod` check so the caller knows which argument is bad.","triggerScenarios":"Constructing `new HttpMethodChangeTransform(fromMethod, toMethod)` with `toMethod` null/empty/whitespace, or transform config that omits/blanks the to-method.","commonSituations":"Config has `from` but missing `to`. Programmatic construction from a config value that defaulted to empty.","solutions":["Supply a valid non-empty HTTP method for `toMethod`.","Guard the value before constructing if sourced from input.","Complete the transform config with both from- and to-methods."],"exampleFix":"// before\nnew HttpMethodChangeTransform(\"POST\", \"\");\n// after\nnew HttpMethodChangeTransform(\"POST\", \"PUT\");","handlingStrategy":"validation","validationCode":"ArgumentException.ThrowIfNullOrEmpty(toMethod);","typeGuard":"static bool IsValidHttpMethod(string? m) =>\n    !string.IsNullOrEmpty(m) && m.All(c => c >= 'A' && c <= 'Z' || c == '-');","tryCatchPattern":null,"preventionTips":["Always supply both from- and to-methods in transform config.","Use ArgumentException.ThrowIfNullOrEmpty on both before constructing.","Validate config completeness at startup."],"tags":["transforms","http-method","argument-validation","yarp"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}