Error: “Cannot use ‘async’ on methods without bodies”. How to force async child overrides?

Whether a method is implemented using async/await or not is an implementation detail. How the method should behave is a contract detail, which should be specified in the normal way.

Note that if you make the method return a Task or a Task<T>, it’s more obvious that it’s meant to be asynchronous, and will probably be hard to implement without being asynchronous.

On the other hand, if there’s an implementation (e.g. for test purposes) where the await expressions would never be incomplete, why would you want to force someone to write an async method with no await calls in anyway? You’re expecting implementations to be IO-bound, but maybe there will be special cases where implementations want to use hard-coded data etc.

Basically you’ve got to handle this in the documentation for the method – if you can’t trust implementers to read that, you’ve got no chance anyway 🙁

Leave a Comment