rspec/rules/S4586/vbnet/rule.adoc
2021-01-27 13:42:22 +01:00

18 lines
502 B
Plaintext

Returning ``++Nothing++`` from a non-``++asyn{cpp}`` ``++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
----