{"record":{"id":"4644f5ca73fdcd23","repo":"microsoft/aspire","slug":"argumentnullexception-for-parameter-path-pathstring-value-is","errorCode":null,"errorMessage":"ArgumentNullException for parameter 'path' (PathString value is null).","messagePattern":"ArgumentNullException for parameter 'path' \\(PathString value is null\\)\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Yarp/ConfigurationBuilder/Transforms/PathTransformExtensions.cs","lineNumber":25,"sourceCode":"using Yarp.ReverseProxy.Transforms;\n\nnamespace Aspire.Hosting.Yarp.Transforms;\n\n/// <summary>\n/// Extensions for adding path transforms.\n/// </summary>\npublic static class PathTransformExtensions\n{\n    /// <summary>\n    /// Adds the transform which sets 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 WithTransformPathSet(this YarpRoute route, PathString path)\n    {\n        if (path.Value is null)\n        {\n            throw new ArgumentNullException(nameof(path));\n        }\n\n        route.Configure(r => r.WithTransformPathSet(path));\n\n        return route;\n    }\n\n    /// <summary>\n    /// Adds the transform which sets the request path with the given value.\n    /// </summary>\n    /// <param name=\"route\">The route to configure.</param>\n    /// <param name=\"path\">The path value to set.</param>\n    /// <returns>The configured <see cref=\"YarpRoute\"/>.</returns>\n    [AspireExport]\n    internal static YarpRoute WithTransformPathSet(this YarpRoute route, string path)\n    {\n        ArgumentNullException.ThrowIfNull(route);\n        ArgumentNullException.ThrowIfNull(path);","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Yarp/ConfigurationBuilder/Transforms/PathTransformExtensions.cs#L7-L43","documentation":"WithTransformPathSet accepts a PathString and requires a non-null Value; a default (empty) PathString has a null Value. The extension explicitly throws ArgumentNullException before delegating to YARP so the failure points at the caller's argument.","triggerScenarios":"Calling WithTransformPathSet(route, default(PathString)) or with a PathString constructed from null (e.g. new PathString(null), or passing a null string that implicitly converts).","commonSituations":"Variable holding the path was null; using default(PathString) as a placeholder; ASP.NET Core PathString accidentally default-initialized; optional configuration value not supplied.","solutions":["Pass a non-empty path string, e.g. WithTransformPathSet(route, \"/newpath\").","Use the string-based overload instead of the PathString overload (the PathString one is even ignored in polyglot app hosts).","Guard the source value before calling: if (string.IsNullOrEmpty(myPath)) throw/return before invoking the transform.","Initialize PathString from validated configuration values rather than raw optional inputs."],"exampleFix":"// before\nvar path = config[\"RewritePath\"]; // may be null\nroute.WithTransformPathSet(new PathString(path));\n// after\nvar path = config[\"RewritePath\"] ?? \"/default-path\";\nroute.WithTransformPathSet(path);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path.Value))\n    throw new ArgumentException(\"path must be non-empty before calling WithTransformPathSet\");","typeGuard":"static bool HasValue(PathString p) => !string.IsNullOrEmpty(p.Value);","tryCatchPattern":"try { route.WithTransformPathSet(path); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"path\") { /* substitute default path */ }","preventionTips":["Prefer string overloads for transforms.","Coalesce optional config values before use.","Never pass default(PathString) as a placeholder."],"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-21T04:17:39.646Z"}