Saturday, March 2, 2019

When a problem seems to lie at an interface in C#, temporarily removing the interface can help in troubleshooting.

I was getting this today:

The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.

 
 

I was calling a method at an interface that returned Task and the method at a class that was wired up to it started out with public async Task, so it seemed like it should work. I was using the await keyword where I called out the method and herein I got the squiggly red line under my line of code in Visual Studio 2019. It turned that out the method wrapping the call did not have the async keyword decorating it and I could not see this until I attempted to directly call the class the interface buffered away.

No comments:

Post a Comment