{"record":{"id":"934befd54277a36b","repo":"restsharp/RestSharp","slug":"request-resource-doesn-t-contain-a-valid-scheme-fo","errorCode":null,"errorMessage":"Request resource doesn't contain a valid scheme for an empty base URL of the client","messagePattern":"Request resource doesn't contain a valid scheme for an empty base URL of the client","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/RestSharp/BuildUriExtensions.cs","lineNumber":93,"sourceCode":"            string GetString(string name, string? value, Func<string, string>? encode) {\n                var val = encode != null && value != null ? encode(value) : value;\n                return val == null ? name : $\"{name}={val}\";\n            }\n\n            string EncodeParameter(Parameter parameter)\n                => !parameter.Encode\n                    ? GetString(parameter.Name!, parameter.Value?.ToString(), null)\n                    : GetString(\n                        client.Options.EncodeQuery(parameter.Name!, client.Options.Encoding),\n                        parameter.Value?.ToString(),\n                        x => client.Options.EncodeQuery(x, client.Options.Encoding)\n                    );\n        }\n    }\n\n    static void DoBuildUriValidations(IRestClient client, RestRequest request) {\n        if (client.Options.BaseUrl == null && !request.Resource.StartsWith(\"http\", StringComparison.InvariantCultureIgnoreCase))\n            throw new ArgumentOutOfRangeException(\n                nameof(request),\n                \"Request resource doesn't contain a valid scheme for an empty base URL of the client\"\n            );\n    }\n}\n","sourceCodeStart":75,"sourceCodeEnd":99,"githubUrl":"https://github.com/restsharp/RestSharp/blob/6a5082169257438cd085f822f050d93256a8e499/src/RestSharp/BuildUriExtensions.cs#L75-L99","documentation":"Thrown by DoBuildUriValidations when the client has no BaseUrl set and the request's Resource does not start with 'http'. Without a base URL the resource must itself be an absolute URL containing the scheme, otherwise the client cannot build a valid request URI.","triggerScenarios":"Creating a RestClient with no BaseUrl (or BaseUrl null) and issuing a request whose Resource is a relative path like '/api/items' instead of a full absolute URL like 'https://host/api/items'.","commonSituations":"Forgot to set RestClientOptions.BaseUrl; intended to pass full URLs per-request but supplied a relative path; BaseUrl was conditionally set from config that resolved to null.","solutions":["Set RestClientOptions.BaseUrl to the API root (e.g. new Uri(\"https://api.host\")).","If using per-request full URLs, ensure each RestRequest.Resource starts with http:// or https://.","Validate that configuration supplying BaseUrl is non-null before constructing the client."],"exampleFix":"// before\nvar client = new RestClient();\nvar req = new RestRequest(\"/api/items\");\n\n// after\nvar client = new RestClient(new RestClientOptions(\"https://api.host\"));\nvar req = new RestRequest(\"/api/items\");","handlingStrategy":"validation","validationCode":"if (client.Options.BaseUrl == null && !request.Resource.StartsWith(\"http\", StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException(\"Set BaseUrl or use an absolute Resource URL\");","typeGuard":null,"tryCatchPattern":"try { await client.ExecuteAsync(request); } catch (ArgumentOutOfRangeException ex) when (ex.Message.Contains(\"valid scheme\")) { /* set BaseUrl or make Resource absolute */ }","preventionTips":["Always set RestClientOptions.BaseUrl when constructing the client.","If BaseUrl is config-driven, assert it is non-null before building the client.","For per-request absolute URLs, ensure Resource starts with http:// or https://."],"tags":["url","configuration","base-url","request"],"backgroundTag":null,"analyzedSha":"6a5082169257438cd085f822f050d93256a8e499","analyzedAt":"2026-08-13T20:38:25.807Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}