I am trying to write a method in my web-api shell. I want to use the "async / await" function so that the user interface is not blocked. Below is a snippet of code in a web api shell.
public static async Task Get<T>(Dictionary<string, string> paramDictionary, string controller)
{
try
{
string absoluteUrl = BaseUrl + controller + "?";
absoluteUrl = paramDictionary.Aggregate(absoluteUrl,
(current, keyValuePair) => current + (keyValuePair.Key + "=" + keyValuePair.Value + "&"));
absoluteUrl = absoluteUrl.TrimEnd('&');
using (HttpClient client = GetClient(absoluteUrl))
{
HttpResponseMessage response = await client.GetAsync(absoluteUrl);
return await response.Content.ReadAsAsync<T>();
}
}
catch (Exception exception)
{
throw exception;
}
}
The problem is that I get a compiler error in the instructions below.
HttpResponseMessage response = await client.GetAsync(absoluteUrl);
It says "Type System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> is not awaitable". After a long search, I can not get rid of this error. Any ideas I'm wrong about? Please, help.
source
share