{"record":{"id":"6cb55fc9a7fd5699","repo":"microsoft/aspire","slug":"argumentnullexception-for-parameter-pattern-pathstring-value","errorCode":null,"errorMessage":"ArgumentNullException for parameter 'pattern' (PathString value is null).","messagePattern":"ArgumentNullException for parameter 'pattern' \\(PathString value is null\\)\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Yarp/ConfigurationBuilder/Transforms/PathTransformExtensions.cs","lineNumber":121,"sourceCode":"    [AspireExport]\n    internal static YarpRoute WithTransformPathRemovePrefix(this YarpRoute route, string prefix)\n    {\n        ArgumentNullException.ThrowIfNull(route);\n        ArgumentNullException.ThrowIfNull(prefix);\n\n        return route.WithTransformPathRemovePrefix(new PathString(prefix));\n    }\n\n    /// <summary>\n    /// Adds the transform which will set the request path with the given value.\n    /// </summary>\n    /// <remarks>This overload is not available in polyglot app hosts. Use the string-based overload instead.</remarks>\n    [AspireExportIgnore(Reason = \"PathString is not ATS-compatible. Use the string-based overload instead.\")]\n    public static YarpRoute WithTransformPathRouteValues(this YarpRoute route, [StringSyntax(\"Route\")] PathString pattern)\n    {\n        if (pattern.Value is null)\n        {\n            throw new ArgumentNullException(nameof(pattern));\n        }\n\n        route.Configure(r => r.WithTransformPathRouteValues(pattern));\n\n        return route;\n    }\n\n    /// <summary>\n    /// Adds the transform which will set the request path with route values.\n    /// </summary>\n    /// <param name=\"route\">The route to configure.</param>\n    /// <param name=\"pattern\">The route pattern to apply.</param>\n    /// <returns>The configured <see cref=\"YarpRoute\"/>.</returns>\n    [AspireExport]\n    internal static YarpRoute WithTransformPathRouteValues(this YarpRoute route, [StringSyntax(\"Route\")] string pattern)\n    {\n        ArgumentNullException.ThrowIfNull(route);\n        ArgumentNullException.ThrowIfNull(pattern);","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Yarp/ConfigurationBuilder/Transforms/PathTransformExtensions.cs#L103-L139","documentation":"WithTransformPathRouteValues takes a route pattern as PathString and rejects a null Value with ArgumentNullException for 'pattern'. The pattern is required because it defines the route template with the {**route_values} style path placeholders YARP expands.","triggerScenarios":"Calling WithTransformPathRouteValues with default(PathString), new PathString(null), or a null string used as the route pattern.","commonSituations":"Pattern stored in nullable config or database column that is empty; null returned from a pattern-resolution helper; typo'd constant left null.","solutions":["Pass a valid route pattern string, e.g. \"/products/{**remainder}\".","Switch to the string-based overload (the PathString overload is ignored in polyglot app hosts).","Coalesce or validate the pattern before calling: string.IsNullOrEmpty check.","Ensure the constant/config source that should hold the pattern actually has a value."],"exampleFix":"// before\nroute.WithTransformPathRouteValues(new PathString(pattern)); // pattern null\n// after\nroute.WithTransformPathRouteValues(pattern ?? \"/products/{**remainder}\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(pattern.Value))\n    throw new ArgumentException(\"pattern must be non-empty before calling WithTransformPathRouteValues\");","typeGuard":"static bool HasValue(PathString p) => !string.IsNullOrEmpty(p.Value);","tryCatchPattern":"try { route.WithTransformPathRouteValues(pattern); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"pattern\") { /* provide fallback pattern */ }","preventionTips":["Define route pattern constants with concrete values.","Use string overloads for transforms.","Validate pattern sources (config/db) return non-null values."],"tags":["yarp","transforms","null-argument"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}