Search code examples
restsharp

I am getting error for RestSharp library for C# .NET unable to return request, IRestResponse is deprecated


I am getting error at the last line since RestSharp has made major breaking changes in their latest release. my methods are failing???

 public RestResponse SendRequest(string url, object requestBody)
    {      
        var client = new RestClient(baseURL + url);
        var request = new RestRequest();
        request.Method = Method.Post;            
        request.AddJsonBody(requestBody);
        return client.ExecuteAsync(request); <= this is the line throwing error message.

Error CS0029 Cannot implicitly convert type 'System.Threading.Tasks.Task<RestSharp.RestResponse>' to 'RestSharp.RestResponse'

this last line is where I am getting error from RestSharp library. Any help is appreciated. The old implementation used to work. Now It started failing after updating to the new RestSharp version.

here is the new documentation https://restsharp.dev/v107/#making-requests


Solution

  • var client = new RestClient(baseURL + url);            
    var request = new RestRequest();
    request.Method = Method.Post;
    request.AddJsonBody(requestBody);
    return client.ExecuteAsync(request).Result;
    

    As per RestSharp this should be the NEW implementation.....