I am trying to write a method in my web api wrapper. I want to make use of "async/await" feature so that UI doesn't get blocked. Below is the code snippet in the web api wrapper.
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 I get compiler error at the statement below.
HttpResponseMessage response = await client.GetAsync(absoluteUrl); It says "Type System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> is not awaitable". After much searching I am not able to get rid of this error. Any ideas where I am going wrong? Please help.

throw exception;will destroy the callstack. Just usethrow;ReadAsAsync<T>. Is that an extension method?Taskin .Net 4.0 does not have the requiredGetAwaitermethod so it cannot be used with async/await. You can use the async targeting pack to add the required methods.try/catch/finallyand other C# control flow statements. Although, you cannotawaitinsidecatch/finally(you can insidetry).