{"record":{"id":"105bfe36394ee8e1","repo":"microsoft/aspire","slug":"argumentnullexception-for-parameter-prefix-pathstring-value","errorCode":null,"errorMessage":"ArgumentNullException for parameter 'prefix' (PathString value is null).","messagePattern":"ArgumentNullException for parameter 'prefix' \\(PathString value is null\\)\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Yarp/ConfigurationBuilder/Transforms/PathTransformExtensions.cs","lineNumber":57,"sourceCode":"    [AspireExport]\n    internal static YarpRoute WithTransformPathSet(this YarpRoute route, string path)\n    {\n        ArgumentNullException.ThrowIfNull(route);\n        ArgumentNullException.ThrowIfNull(path);\n\n        return route.WithTransformPathSet(new PathString(path));\n    }\n\n    /// <summary>\n    /// Adds the transform which will prefix 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 WithTransformPathPrefix(this YarpRoute route, PathString prefix)\n    {\n        if (prefix.Value is null)\n        {\n            throw new ArgumentNullException(nameof(prefix));\n        }\n\n        route.Configure(r => r.WithTransformPathPrefix(prefix));\n\n        return route;\n    }\n\n    /// <summary>\n    /// Adds the transform which will prefix the request path with the given value.\n    /// </summary>\n    /// <param name=\"route\">The route to configure.</param>\n    /// <param name=\"prefix\">The path prefix to add.</param>\n    /// <returns>The configured <see cref=\"YarpRoute\"/>.</returns>\n    [AspireExport]\n    internal static YarpRoute WithTransformPathPrefix(this YarpRoute route, string prefix)\n    {\n        ArgumentNullException.ThrowIfNull(route);\n        ArgumentNullException.ThrowIfNull(prefix);","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Yarp/ConfigurationBuilder/Transforms/PathTransformExtensions.cs#L39-L75","documentation":"WithTransformPathPrefix requires a PathString with a non-null Value; a default PathString has null Value. The extension validates up front and throws ArgumentNullException for 'prefix' to surface the problem at the call site.","triggerScenarios":"Calling WithTransformPathPrefix with default(PathString), new PathString(null), or a null string implicitly converted to PathString.","commonSituations":"Prefix read from nullable config/appsettings key that is absent; a variable initialized with default(PathString); null return from a helper that resolves the prefix.","solutions":["Pass a non-empty prefix string such as \"/api\".","Prefer the string-based overload; the PathString overload is not available in polyglot app hosts anyway.","Coalesce null config values: var prefix = config[\"PathPrefix\"] ?? \"/api\".","Validate the prefix with string.IsNullOrEmpty before constructing the PathString."],"exampleFix":"// before\nroute.WithTransformPathPrefix(new PathString(prefixOrNull));\n// after\nroute.WithTransformPathPrefix(prefixOrNull ?? \"/prefix\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(prefix.Value))\n    throw new ArgumentException(\"prefix must be non-empty before calling WithTransformPathPrefix\");","typeGuard":"static bool HasValue(PathString p) => !string.IsNullOrEmpty(p.Value);","tryCatchPattern":"try { route.WithTransformPathPrefix(prefix); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"prefix\") { /* skip transform or use default */ }","preventionTips":["Validate config-derived prefixes before use.","Use string overloads for transforms.","Skip adding transforms whose inputs are absent rather than passing null."],"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"}