I have the function below. it returns a "simpleresult" which I've also
included the definition of below.
In VS2005 (after upgrading the project), I get a warning indicating that
Function 'CloseVantive' doesn't return a value on all code paths. A null
reference exception could occur at run time when the result is used.
The code runs fine. But why do I get this message? How do i get rid of it?
The only thing I found is if i add a line at the start of the function that
says:
CloseVantive=New SimpleResult but I don't see why that would be necessary.
Function CloseVantive(ByVal connection As Integer) As SimpleResult
Dim vanresult As Integer
Try
If (connection > 0) Then
IncrementRequestCounterNamed("Vantive Connections Closed")
vanresult = VanCloseConnection(connection, 0, 0)
If (vanresult < 0) Then
CloseVantive.ResultDescription = "VanAPI Error# " +
vanresult.ToString + " (" + TranslateVANError(vanresult) + ") - when closing
connection (CloseVantive)."
CloseVantive.APIResult = vanresult
End If
End If
Catch e As Exception
Throw New Exception("Error in CloseVantive.", e)
End Try
End Function
Public Structure SimpleResult
Dim APIResult As Integer ' 0 = success. <0 indicates
error.
Dim ResultDescription As String ' If error, text description of
error.
End Structure