catching NullReferenceException that crashes IIS website










0















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:gameServerSecureUserCheck.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!










share|improve this question
























  • @AndrewMorton thanks for catching that. I wrote the code in by hand instead of copying and pasting from the project and mistyped. I fixed it, thanks!

    – SkyeBoniwell
    Nov 14 '18 at 13:41






  • 1





    Where is secureData initialised? Could it be that when the application pool is recycled, it gets lost? Can you reinitialise it if it is Nothing?

    – Andrew Morton
    Nov 14 '18 at 15:50











  • @AndrewMorton I have updated the code to show how it's initialized. Thanks!

    – SkyeBoniwell
    Nov 14 '18 at 18:54















0















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:gameServerSecureUserCheck.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!










share|improve this question
























  • @AndrewMorton thanks for catching that. I wrote the code in by hand instead of copying and pasting from the project and mistyped. I fixed it, thanks!

    – SkyeBoniwell
    Nov 14 '18 at 13:41






  • 1





    Where is secureData initialised? Could it be that when the application pool is recycled, it gets lost? Can you reinitialise it if it is Nothing?

    – Andrew Morton
    Nov 14 '18 at 15:50











  • @AndrewMorton I have updated the code to show how it's initialized. Thanks!

    – SkyeBoniwell
    Nov 14 '18 at 18:54













0












0








0








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:gameServerSecureUserCheck.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!










share|improve this question
















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:gameServerSecureUserCheck.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!







vb.net .net-4.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 18:57







SkyeBoniwell

















asked Nov 14 '18 at 13:11









SkyeBoniwellSkyeBoniwell

2,17074488




2,17074488












  • @AndrewMorton thanks for catching that. I wrote the code in by hand instead of copying and pasting from the project and mistyped. I fixed it, thanks!

    – SkyeBoniwell
    Nov 14 '18 at 13:41






  • 1





    Where is secureData initialised? Could it be that when the application pool is recycled, it gets lost? Can you reinitialise it if it is Nothing?

    – Andrew Morton
    Nov 14 '18 at 15:50











  • @AndrewMorton I have updated the code to show how it's initialized. Thanks!

    – SkyeBoniwell
    Nov 14 '18 at 18:54

















  • @AndrewMorton thanks for catching that. I wrote the code in by hand instead of copying and pasting from the project and mistyped. I fixed it, thanks!

    – SkyeBoniwell
    Nov 14 '18 at 13:41






  • 1





    Where is secureData initialised? Could it be that when the application pool is recycled, it gets lost? Can you reinitialise it if it is Nothing?

    – Andrew Morton
    Nov 14 '18 at 15:50











  • @AndrewMorton I have updated the code to show how it's initialized. Thanks!

    – SkyeBoniwell
    Nov 14 '18 at 18:54
















@AndrewMorton thanks for catching that. I wrote the code in by hand instead of copying and pasting from the project and mistyped. I fixed it, thanks!

– SkyeBoniwell
Nov 14 '18 at 13:41





@AndrewMorton thanks for catching that. I wrote the code in by hand instead of copying and pasting from the project and mistyped. I fixed it, thanks!

– SkyeBoniwell
Nov 14 '18 at 13:41




1




1





Where is secureData initialised? Could it be that when the application pool is recycled, it gets lost? Can you reinitialise it if it is Nothing?

– Andrew Morton
Nov 14 '18 at 15:50





Where is secureData initialised? Could it be that when the application pool is recycled, it gets lost? Can you reinitialise it if it is Nothing?

– Andrew Morton
Nov 14 '18 at 15:50













@AndrewMorton I have updated the code to show how it's initialized. Thanks!

– SkyeBoniwell
Nov 14 '18 at 18:54





@AndrewMorton I have updated the code to show how it's initialized. Thanks!

– SkyeBoniwell
Nov 14 '18 at 18:54












1 Answer
1






active

oldest

votes


















1














First, you should use Option Strict On. It will help you get all the types matching up correctly, which leads to fewer errors and faster code.



Now, onto the main issue. If you can do something useful about a problem encountered while the program is running, you should. In this case, you can re-initialise the data if it has been lost:



Public Sub New()
Dim ds As Data.DataSet

If Session("secureData") Is Nothing Then
ds = getSecureDS(gameID)
Session("secureData") = ds
Else
ds = DirectCast(Session("secureData"), Data.DataSet)
End If

If Not ds.Tables.Contains("GameInfo") Then
Throw New System.ArgumentException("The secureData must contain [GameInfo] table.")
End If

' more code...

End Sub


Please also notice the cleaner way of checking if a particular table exists, although I suggest it properly belongs in the getSecureDS method.



If the dataset applies to all users of the site, you should consider using System.Runtime.Caching instead of session state.






share|improve this answer























  • Thank you. I do have one dataset that applies to all users. When I populate that, I do use Page.Application.Lock(), populate the dataset, then Page.Application.Unlock(). Maybe that's a problem too?

    – SkyeBoniwell
    Nov 15 '18 at 17:03











  • Andrew, do you think adding the check for the table would help with the app causing IIS to crash? Thanks!

    – SkyeBoniwell
    Nov 15 '18 at 17:16






  • 1





    @SkyeBoniwell If you had the dataset cached once for all users, then you could (call a method to) load it in the Application_Start event handler. I don't know if using Application.Lock() could cause a problem, I would not expect it to. Do have a careful read of the System.Runtime.Caching documentation if you use it.

    – Andrew Morton
    Nov 15 '18 at 18:26







  • 1





    @SkyeBoniwell I only put in the check for the table because it was in the code sample in the question. If there is no way the table could disappear from the dataset, then it doesn't really need the check.

    – Andrew Morton
    Nov 15 '18 at 18:28










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301054%2fcatching-nullreferenceexception-that-crashes-iis-website%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














First, you should use Option Strict On. It will help you get all the types matching up correctly, which leads to fewer errors and faster code.



Now, onto the main issue. If you can do something useful about a problem encountered while the program is running, you should. In this case, you can re-initialise the data if it has been lost:



Public Sub New()
Dim ds As Data.DataSet

If Session("secureData") Is Nothing Then
ds = getSecureDS(gameID)
Session("secureData") = ds
Else
ds = DirectCast(Session("secureData"), Data.DataSet)
End If

If Not ds.Tables.Contains("GameInfo") Then
Throw New System.ArgumentException("The secureData must contain [GameInfo] table.")
End If

' more code...

End Sub


Please also notice the cleaner way of checking if a particular table exists, although I suggest it properly belongs in the getSecureDS method.



If the dataset applies to all users of the site, you should consider using System.Runtime.Caching instead of session state.






share|improve this answer























  • Thank you. I do have one dataset that applies to all users. When I populate that, I do use Page.Application.Lock(), populate the dataset, then Page.Application.Unlock(). Maybe that's a problem too?

    – SkyeBoniwell
    Nov 15 '18 at 17:03











  • Andrew, do you think adding the check for the table would help with the app causing IIS to crash? Thanks!

    – SkyeBoniwell
    Nov 15 '18 at 17:16






  • 1





    @SkyeBoniwell If you had the dataset cached once for all users, then you could (call a method to) load it in the Application_Start event handler. I don't know if using Application.Lock() could cause a problem, I would not expect it to. Do have a careful read of the System.Runtime.Caching documentation if you use it.

    – Andrew Morton
    Nov 15 '18 at 18:26







  • 1





    @SkyeBoniwell I only put in the check for the table because it was in the code sample in the question. If there is no way the table could disappear from the dataset, then it doesn't really need the check.

    – Andrew Morton
    Nov 15 '18 at 18:28















1














First, you should use Option Strict On. It will help you get all the types matching up correctly, which leads to fewer errors and faster code.



Now, onto the main issue. If you can do something useful about a problem encountered while the program is running, you should. In this case, you can re-initialise the data if it has been lost:



Public Sub New()
Dim ds As Data.DataSet

If Session("secureData") Is Nothing Then
ds = getSecureDS(gameID)
Session("secureData") = ds
Else
ds = DirectCast(Session("secureData"), Data.DataSet)
End If

If Not ds.Tables.Contains("GameInfo") Then
Throw New System.ArgumentException("The secureData must contain [GameInfo] table.")
End If

' more code...

End Sub


Please also notice the cleaner way of checking if a particular table exists, although I suggest it properly belongs in the getSecureDS method.



If the dataset applies to all users of the site, you should consider using System.Runtime.Caching instead of session state.






share|improve this answer























  • Thank you. I do have one dataset that applies to all users. When I populate that, I do use Page.Application.Lock(), populate the dataset, then Page.Application.Unlock(). Maybe that's a problem too?

    – SkyeBoniwell
    Nov 15 '18 at 17:03











  • Andrew, do you think adding the check for the table would help with the app causing IIS to crash? Thanks!

    – SkyeBoniwell
    Nov 15 '18 at 17:16






  • 1





    @SkyeBoniwell If you had the dataset cached once for all users, then you could (call a method to) load it in the Application_Start event handler. I don't know if using Application.Lock() could cause a problem, I would not expect it to. Do have a careful read of the System.Runtime.Caching documentation if you use it.

    – Andrew Morton
    Nov 15 '18 at 18:26







  • 1





    @SkyeBoniwell I only put in the check for the table because it was in the code sample in the question. If there is no way the table could disappear from the dataset, then it doesn't really need the check.

    – Andrew Morton
    Nov 15 '18 at 18:28













1












1








1







First, you should use Option Strict On. It will help you get all the types matching up correctly, which leads to fewer errors and faster code.



Now, onto the main issue. If you can do something useful about a problem encountered while the program is running, you should. In this case, you can re-initialise the data if it has been lost:



Public Sub New()
Dim ds As Data.DataSet

If Session("secureData") Is Nothing Then
ds = getSecureDS(gameID)
Session("secureData") = ds
Else
ds = DirectCast(Session("secureData"), Data.DataSet)
End If

If Not ds.Tables.Contains("GameInfo") Then
Throw New System.ArgumentException("The secureData must contain [GameInfo] table.")
End If

' more code...

End Sub


Please also notice the cleaner way of checking if a particular table exists, although I suggest it properly belongs in the getSecureDS method.



If the dataset applies to all users of the site, you should consider using System.Runtime.Caching instead of session state.






share|improve this answer













First, you should use Option Strict On. It will help you get all the types matching up correctly, which leads to fewer errors and faster code.



Now, onto the main issue. If you can do something useful about a problem encountered while the program is running, you should. In this case, you can re-initialise the data if it has been lost:



Public Sub New()
Dim ds As Data.DataSet

If Session("secureData") Is Nothing Then
ds = getSecureDS(gameID)
Session("secureData") = ds
Else
ds = DirectCast(Session("secureData"), Data.DataSet)
End If

If Not ds.Tables.Contains("GameInfo") Then
Throw New System.ArgumentException("The secureData must contain [GameInfo] table.")
End If

' more code...

End Sub


Please also notice the cleaner way of checking if a particular table exists, although I suggest it properly belongs in the getSecureDS method.



If the dataset applies to all users of the site, you should consider using System.Runtime.Caching instead of session state.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 19:40









Andrew MortonAndrew Morton

15.5k53151




15.5k53151












  • Thank you. I do have one dataset that applies to all users. When I populate that, I do use Page.Application.Lock(), populate the dataset, then Page.Application.Unlock(). Maybe that's a problem too?

    – SkyeBoniwell
    Nov 15 '18 at 17:03











  • Andrew, do you think adding the check for the table would help with the app causing IIS to crash? Thanks!

    – SkyeBoniwell
    Nov 15 '18 at 17:16






  • 1





    @SkyeBoniwell If you had the dataset cached once for all users, then you could (call a method to) load it in the Application_Start event handler. I don't know if using Application.Lock() could cause a problem, I would not expect it to. Do have a careful read of the System.Runtime.Caching documentation if you use it.

    – Andrew Morton
    Nov 15 '18 at 18:26







  • 1





    @SkyeBoniwell I only put in the check for the table because it was in the code sample in the question. If there is no way the table could disappear from the dataset, then it doesn't really need the check.

    – Andrew Morton
    Nov 15 '18 at 18:28

















  • Thank you. I do have one dataset that applies to all users. When I populate that, I do use Page.Application.Lock(), populate the dataset, then Page.Application.Unlock(). Maybe that's a problem too?

    – SkyeBoniwell
    Nov 15 '18 at 17:03











  • Andrew, do you think adding the check for the table would help with the app causing IIS to crash? Thanks!

    – SkyeBoniwell
    Nov 15 '18 at 17:16






  • 1





    @SkyeBoniwell If you had the dataset cached once for all users, then you could (call a method to) load it in the Application_Start event handler. I don't know if using Application.Lock() could cause a problem, I would not expect it to. Do have a careful read of the System.Runtime.Caching documentation if you use it.

    – Andrew Morton
    Nov 15 '18 at 18:26







  • 1





    @SkyeBoniwell I only put in the check for the table because it was in the code sample in the question. If there is no way the table could disappear from the dataset, then it doesn't really need the check.

    – Andrew Morton
    Nov 15 '18 at 18:28
















Thank you. I do have one dataset that applies to all users. When I populate that, I do use Page.Application.Lock(), populate the dataset, then Page.Application.Unlock(). Maybe that's a problem too?

– SkyeBoniwell
Nov 15 '18 at 17:03





Thank you. I do have one dataset that applies to all users. When I populate that, I do use Page.Application.Lock(), populate the dataset, then Page.Application.Unlock(). Maybe that's a problem too?

– SkyeBoniwell
Nov 15 '18 at 17:03













Andrew, do you think adding the check for the table would help with the app causing IIS to crash? Thanks!

– SkyeBoniwell
Nov 15 '18 at 17:16





Andrew, do you think adding the check for the table would help with the app causing IIS to crash? Thanks!

– SkyeBoniwell
Nov 15 '18 at 17:16




1




1





@SkyeBoniwell If you had the dataset cached once for all users, then you could (call a method to) load it in the Application_Start event handler. I don't know if using Application.Lock() could cause a problem, I would not expect it to. Do have a careful read of the System.Runtime.Caching documentation if you use it.

– Andrew Morton
Nov 15 '18 at 18:26






@SkyeBoniwell If you had the dataset cached once for all users, then you could (call a method to) load it in the Application_Start event handler. I don't know if using Application.Lock() could cause a problem, I would not expect it to. Do have a careful read of the System.Runtime.Caching documentation if you use it.

– Andrew Morton
Nov 15 '18 at 18:26





1




1





@SkyeBoniwell I only put in the check for the table because it was in the code sample in the question. If there is no way the table could disappear from the dataset, then it doesn't really need the check.

– Andrew Morton
Nov 15 '18 at 18:28





@SkyeBoniwell I only put in the check for the table because it was in the code sample in the question. If there is no way the table could disappear from the dataset, then it doesn't really need the check.

– Andrew Morton
Nov 15 '18 at 18:28

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301054%2fcatching-nullreferenceexception-that-crashes-iis-website%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党