Returning Nothing
from a non-Async
Task
/Task(Of TResult)
procedure will cause a
NullReferenceException
at runtime if the procedure is awaited. This problem can be avoided by returning Task.CompletedTask
or Task.FromResult(Of TResult)(Nothing)
respectively.
Public Function DoFooAsync() As Task
Return Nothing ' Noncompliant: Causes a NullReferenceException if awaited.
End Function
Public Async Function Main() As Task
Await DoFooAsync() ' NullReferenceException
End Function