microsoft/aspire · error · ArgumentNullException

ArgumentNullException for parameter 'path' (PathString…

Error message

ArgumentNullException for parameter 'path' (PathString value is null).

What it means

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.

Solutions

  1. Pass a non-empty path string, e.g. WithTransformPathSet(route, "/newpath").
  2. Use the string-based overload instead of the PathString overload (the PathString one is even ignored in polyglot app hosts).
  3. Guard the source value before calling: if (string.IsNullOrEmpty(myPath)) throw/return before invoking the transform.
  4. Initialize PathString from validated configuration values rather than raw optional inputs.

Example fix

// before
var path = config["RewritePath"]; // may be null
route.WithTransformPathSet(new PathString(path));
// after
var path = config["RewritePath"] ?? "/default-path";
route.WithTransformPathSet(path);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(path.Value))
    throw new ArgumentException("path must be non-empty before calling WithTransformPathSet");

Type guard

static bool HasValue(PathString p) => !string.IsNullOrEmpty(p.Value);

Try / catch

try { route.WithTransformPathSet(path); }
catch (ArgumentNullException ex) when (ex.ParamName == "path") { /* substitute default path */ }

Prevention

When it happens

Trigger: 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).

Common situations: Variable holding the path was null; using default(PathString) as a placeholder; ASP.NET Core PathString accidentally default-initialized; optional configuration value not supplied.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/4644f5ca73fdcd23. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Yarp/ConfigurationBuilder/Transforms/PathTransformExtensions.cs:25

using Yarp.ReverseProxy.Transforms;

namespace Aspire.Hosting.Yarp.Transforms;

/// <summary>
/// Extensions for adding path transforms.
/// </summary>
public static class PathTransformExtensions
{
    /// <summary>
    /// Adds the transform which sets the request path with the given value.
    /// </summary>
    /// <remarks>This overload is not available in polyglot app hosts. Use the string-based overload instead.</remarks>
    [AspireExportIgnore(Reason = "PathString is not ATS-compatible. Use the string-based overload instead.")]
    public static YarpRoute WithTransformPathSet(this YarpRoute route, PathString path)
    {
        if (path.Value is null)
        {
            throw new ArgumentNullException(nameof(path));
        }

        route.Configure(r => r.WithTransformPathSet(path));

        return route;
    }

    /// <summary>
    /// Adds the transform which sets the request path with the given value.
    /// </summary>
    /// <param name="route">The route to configure.</param>
    /// <param name="path">The path value to set.</param>
    /// <returns>The configured <see cref="YarpRoute"/>.</returns>
    [AspireExport]
    internal static YarpRoute WithTransformPathSet(this YarpRoute route, string path)
    {
        ArgumentNullException.ThrowIfNull(route);
        ArgumentNullException.ThrowIfNull(path);

View on GitHub (pinned to 25830f84bd)