I have a .Net 4.6 web application that has a chronic yet intermittent problem where an error occurs, always at the same spot, which crashes IIS.
The web app is used everyday, but this error doesn't happen everyday. But when it does error out and crash the website, it's always on the same line.
Here's the error:
[NullReferenceException: Object reference not set to an instance of an object.] SecureUserCheck..ctor(Dataset secureData) in e:\gameServer\SecureUserCheck.vb:160
Here is how "ds" is initialized:
Dim ds As Data.DataSet = Session("secureData")
If IsNothing(ds) Then
ds = getSecureDS(gameID)
Session("secureData") = ds
End If
Here is SecureUserCheck.vb with line 160 below:
inhSec = New SecureUserCheck(ds)
Public Sub New(ByVal secureData As DataSet)
If secureData Is Nothing Then
Throw New System.ArgumentException("secureData in empty.")
Else
startTime = DateTime.Now
Try
myGameInfo = secureData.Tables("GameInfo") // LINE 160
Catch ex As Exception
Throw New System.ArgumentException("The secureData must contain [GameInfo] table.")
End Try
With myGameInfoRows(0)
...fill variables
End With
I tried wrapping it in a Try Catch block, but that never seems to be thrown. The error will still pop up and crash IIS.
Is there anything I can do to check and make sure the datasets and datatables exist, or not null so that IIS doesn't crash?
Thanks!