Why is this an issue?
Returning Nothing
from a non-async
Task
/Task(Of T)
method will cause a
NullReferenceException
at runtime. This problem can be avoided by returning Task.FromResult(Of T)(Nothing)
instead.
Noncompliant code example
Public Function GetFooAsync() As Task(Of Object)
Return Nothing
End Function
Compliant solution
Public Function GetFooAsync() As Task(Of Object)
Return Task.FromResult(Of Object)(Nothing)
End Function