Situation is pretty simple - I wrote an extension method and made it async with return type Task
. But when I try to call it using await, compiler throw
The error message is pretty clear: the method where you're calling the extension method should be marked as async
.
public Task<string> MyExtension(this string s) { ... }
public async Task MyCallingMethod()
{
string result = await "hi".MyExtension();
}
Re-reading this part should make much more sense now:
"The 'await' operator can only be used within an async method. "