{"record":{"id":"f5308be2795c4858","repo":"restsharp/RestSharp","slug":"both-baseurl-and-resource-are-empty","errorCode":null,"errorMessage":"Both BaseUrl and Resource are empty","messagePattern":"Both BaseUrl and Resource are empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/RestSharp/Request/UriExtensions.cs","lineNumber":29,"sourceCode":"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// \n\nusing RestSharp.Extensions;\n\nnamespace RestSharp;\n\nstatic class UriExtensions {\n    public static Uri MergeBaseUrlAndResource(this Uri? baseUrl, string? resource) {\n        var assembled = resource;\n\n        if (assembled.IsNotEmpty() && assembled[0] == '/') assembled = assembled[1..];\n\n        if (baseUrl == null || baseUrl.AbsoluteUri.IsEmpty()) {\n            return assembled.IsNotEmpty()\n                ? new Uri(assembled)\n                : throw new ArgumentException(\"Both BaseUrl and Resource are empty\", nameof(resource));\n        }\n\n        var usingBaseUri = baseUrl.AbsoluteUri[^1] == '/' || assembled.IsEmpty() ? baseUrl : new(baseUrl.AbsoluteUri + \"/\");\n\n#if NETSTANDARD2_0\n        return !string.IsNullOrWhiteSpace(assembled) ? new(usingBaseUri, assembled, true) : baseUrl;\n#else\n        return !string.IsNullOrWhiteSpace(assembled) ? new(usingBaseUri, assembled) : baseUrl;\n#endif\n    }\n\n    public static Uri AddQueryString(this Uri uri, string? query) {\n        if (query == null) return uri;\n\n        var builder = new UriBuilder(uri);\n        builder.Query = builder.Query.Length > 1 ? $\"{builder.Query[1..]}&{query}\" : query;\n\n        return builder.Uri;","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/restsharp/RestSharp/blob/6a5082169257438cd085f822f050d93256a8e499/src/RestSharp/Request/UriExtensions.cs#L11-L47","documentation":"UriExtensions.MergeBaseUrlAndResource throws ArgumentException when both the client BaseUrl is null/empty and the request Resource is null/empty. RestSharp needs at least one of them to form a request URI; with neither, there is no destination to send to.","triggerScenarios":"Creating a RestClient without a BaseUrl (e.g. new RestClient() with default options) and executing a RestRequest whose Resource string is null or empty. Also when BaseUrl is set to an empty Uri.","commonSituations":"Forgetting to set BaseUrl on RestClientOptions; constructing a RestClient from an HttpClient without a base address and then issuing a request with no resource; passing a relative request with no resource expecting the BaseUrl alone to suffice but BaseUrl is missing too.","solutions":["Set RestClientOptions.BaseUrl (or use the RestClient(Uri baseUrl) constructor).","Provide a non-empty Resource string on the RestRequest.","At minimum ensure one of BaseUrl or Resource is non-empty before calling ExecuteAsync."],"exampleFix":"// before\nvar client = new RestClient(); // no BaseUrl\nvar req = new RestRequest();     // no Resource\nawait client.ExecuteAsync(req); // throws\n\n// after\nvar client = new RestClient(new Uri(\"https://api.example.com\"));\nvar req = new RestRequest(\"/items\");\nawait client.ExecuteAsync(req);","handlingStrategy":"validation","validationCode":"if ((client.Options.BaseUrl is null || string.IsNullOrEmpty(client.Options.BaseUrl.AbsoluteUri))\n    && string.IsNullOrEmpty(request.Resource))\n    throw new InvalidOperationException(\"Set RestClientOptions.BaseUrl or a non-empty RestRequest.Resource\");","typeGuard":null,"tryCatchPattern":"try {\n    await client.ExecuteAsync(request);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"BaseUrl and Resource are empty\")) {\n    // configure base URL/resource then retry\n}","preventionTips":["Always set RestClientOptions.BaseUrl at client construction.","Provide a Resource on every RestRequest unless BaseUrl is a complete endpoint.","Validate one of the two is non-empty in a shared request-build helper."],"tags":["uri","base-url","request","configuration","argument"],"backgroundTag":null,"analyzedSha":"6a5082169257438cd085f822f050d93256a8e499","analyzedAt":"2026-08-13T20:38:25.807Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}