{"record":{"id":"792d4206b25c862f","repo":"dotnet/yarp","slug":"nameof-routevaluekey-cannot-be-null-or-empty","errorCode":null,"errorMessage":"'{nameof(routeValueKey)}' cannot be null or empty.","messagePattern":"'(.+?)' cannot be null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ReverseProxy/Transforms/QueryParameterFromRouteTransform.cs","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT license.\n\nusing System;\n\nnamespace Yarp.ReverseProxy.Transforms;\n\npublic class QueryParameterRouteTransform : QueryParameterTransform\n{\n    public QueryParameterRouteTransform(QueryStringTransformMode mode, string key, string routeValueKey)\n        : base(mode, key)\n    {\n        if (string.IsNullOrEmpty(key))\n        {\n            throw new ArgumentException($\"'{nameof(key)}' cannot be null or empty.\", nameof(key));\n        }\n\n        if (string.IsNullOrEmpty(routeValueKey))\n        {\n            throw new ArgumentException($\"'{nameof(routeValueKey)}' cannot be null or empty.\", nameof(routeValueKey));\n        }\n\n        RouteValueKey = routeValueKey;\n    }\n\n    internal string RouteValueKey { get; }\n\n    /// <inheritdoc/>\n    protected override string? GetValue(RequestTransformContext context)\n    {\n        var routeValues = context.HttpContext.Request.RouteValues;\n        if (!routeValues.TryGetValue(RouteValueKey, out var value))\n        {\n            return null;\n        }\n\n        return value?.ToString();\n    }","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Transforms/QueryParameterFromRouteTransform.cs#L2-L38","documentation":"Thrown by the QueryParameterRouteTransform constructor when `routeValueKey` is null or empty. This transform pulls a value from route values by name; a blank route-value key cannot resolve a value, so it is rejected as ArgumentException.","triggerScenarios":"Constructing `new QueryParameterRouteTransform(mode, key, routeValueKey)` with `routeValueKey` null/empty, or transform config that omits the route value key.","commonSituations":"Config sets a query-from-route transform but the route parameter name is missing or misspelled. The route template does not define the referenced parameter.","solutions":["Provide a non-empty `routeValueKey` that matches a parameter in the route template.","Cross-check the route template (`{userId}`) against the configured routeValueKey.","Validate config before constructing the transform."],"exampleFix":"// before\nnew QueryParameterRouteTransform(QueryStringTransformMode.Set, \"uid\", \"\");\n// after\nnew QueryParameterRouteTransform(QueryStringTransformMode.Set, \"uid\", \"userId\");","handlingStrategy":"validation","validationCode":"ArgumentException.ThrowIfNullOrEmpty(routeValueKey);","typeGuard":"static bool RouteHasParameter(string template, string routeValueKey) =>\n    template.Contains($\"{{{routeValueKey}}}\");","tryCatchPattern":null,"preventionTips":["Ensure routeValueKey matches a parameter in the route template.","Validate config before constructing the transform.","Document which route parameters the route exposes."],"tags":["transforms","query-string","routing","argument-validation","yarp"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}