Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace name "IRestResponse" could not be found (are you missing a using directive or an assembly reference?)

I have a problem with IRestResponse in the below:

public async Task<CezanneToken> GetAccessToken()
{
    var client = new RestClient(WebConfigurationManager.AppSettings["TokenUrl"]);
    var request = new RestRequest();
    request.Method = Method.Post;
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("content-type", "application/x-www-form-urlencoded");
    request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=" + WebConfigurationManager.AppSettings["ClientId"] + "&client_secret=" + WebConfigurationManager.AppSettings["ClientSecret"] + "", ParameterType.RequestBody);

    IRestResponse response = await client.ExecuteAsync(request);
    string serStatus = ((RestResponseBase)response).Content;
    CezanneToken details = JsonConvert.DeserializeObject<CezanneToken>(serStatus);
    string Token = details.access_token;
    
    return details;
}

IRestResponse throws

The type or namespace name "IRestResponse" could not be found (are you missing a using directive or an assembly reference?) I cannot make it work. IntelliSense suggest to go with RestResponse> instead of IRestResponse.

But when I go with RestResponse I get Bad Request on the response.

The code sample above is "translated" from Visual Basic but it works just fine in VB. I don't know if the problem with the Bad Request comes from using RestResponse but I assume IRestResponse is needed just as in VB.

I've also seen people using IRestResponse but it just doesn't work for me. I have the using RestSharp; but do I need something else as well?

like image 446
Ivan Gechev Avatar asked Feb 01 '26 22:02

Ivan Gechev


2 Answers

You will need to downgrade the RestSharp NuGet package (<=106.15).

RestSharp got a major upgrade in v107, a Migration Guide is available.

Depercated interfaces where removed in v107, including:

  • IRestRequest
  • IRestResponse
  • IHttp

Documentation of where classes/interfaces were relocated can be found here

like image 131
Alexey Zimarev Avatar answered Feb 03 '26 11:02

Alexey Zimarev


Downrev to 106.15 worked for me.

like image 22
Shepster68 Avatar answered Feb 03 '26 12:02

Shepster68