The 'async' modifier can only be used in methods that have a body.
Problem
I declared a method in my interface as follows.
public interface IHttpService
{
public async Task<HttpResponseWrapper<Object>> Post<T>(string url, T data);
}
I am getting the following error when I compile my code
"The 'async' modifier can only be used in methods that have a body."
Solution
The error can be fixed just by removing the async modifier from the method declaration. So the solution is to declare the method signature as follows.
public interface IHttpService
{
public Task<HttpResponseWrapper<Object>> Post<T>(string url, T data);
}
In C#, an interface cannot specify a method must be implemented as asynchronous. When you implement the interface you can add the async modifier as follows
public class HttpService : IHttpService
{
public async Task<HttpResponseWrapper<object>> Post<T>(string url, T data)
{
throw new NotImplementedException();
}
}