Click here to Skip to main content
15,358,239 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating an ASP.Net website with VB.Net as code behind and this is the error that appears from the published version on a web server (this does not appear when run directly from the code or from the published version on the IIS server):

error message screenshot

This is a snippet from the controller:

Function Index(ByVal pSurveyName As String) As ActionResult
            If IsNothing(pSurveyName) Then
                Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
            End If
            Dim l_question As Object = GetQuestion()
            Return View(l_question)
        Catch ex As Exception
            Call ExceptionHandler(ex)
            Return View()
        End Try
    End Function

    Function GetQuestion() As Object
        Dim l_questionnaire = Session("ActiveQuestionnaire")
        Dim l_surveySession = Session("SurveySession")
        Dim l_redirectQueue = Session("RedirectQueue")
        Dim l_sessionAnswers = Session("SessionAnswers")
        Dim l_CurrentQuestion As CurrentItem = New CurrentItem
        Dim l_Choices As List(Of Choice) = New List(Of Choice)
        Dim l_TempDBQuestions = db.Questions
        Dim l_TempDBChildQuestions = db.ChildQuestions
        Dim l_TempDBChoices = db.Choices
        Dim l_tempFiltered_Q
        Dim li_questionnaireID As Integer
        Dim li_questionCtr As Integer
        Dim li_total_NoOfQuestion As Integer = 0
        Dim li_resultCount As Integer = 0
        Dim li_childQID As Integer = 0
        Dim ls_prevAnswer As String = ""
        Dim ls_err As String = ""
            li_questionnaireID = l_questionnaire.ID
            li_questionCtr = l_surveySession.QuestionCtr

            If Session("Back") = False Then
                li_questionCtr = GetQuestionCtr(NEXT_QUESTION, l_surveySession, l_redirectQueue, l_sessionAnswers,, ls_prevAnswer)
                Dim l_current = Session("CurrentQuestion")
                li_questionCtr = GetQuestionCtr(PREVIOUS_QUESTION, l_surveySession, l_redirectQueue, l_sessionAnswers, l_current, ls_prevAnswer)
            End If

            l_tempFiltered_Q = l_TempDBQuestions.Where(Function(q) q.QuestionnaireID.Equals(li_questionnaireID) And q.QuestionOrder.Equals(li_questionCtr))
            li_resultCount = l_TempDBQuestions.Where(Function(q) q.QuestionnaireID.Equals(li_questionnaireID) And q.QuestionOrder.Equals(li_questionCtr)).Count

            If li_resultCount = 0 Then
                l_tempFiltered_Q = l_TempDBChildQuestions.Where(Function(q) q.QuestionnaireID.Equals(li_questionnaireID) And q.QuestionOrder.Equals(li_questionCtr))
                Session("FrmChildQuestions") = True
                Session("FrmChildQuestions") = False
            End If

            For Each item In l_tempFiltered_Q
                'item could be from Questions or ChildQuestions
                If li_resultCount = 0 Then
                    Session("IsNextQuestionChild") = item.IsNextQuestionChild
                End If
                With l_CurrentQuestion
                    .ID = item.ID
                    .QuestionnaireID = item.QuestionnaireID
                    .QuestionOrder = item.QuestionOrder
                    .Description = item.Description
                    .AnswerType = item.AnswerType
                    .AllowMultipleAnswers = item.AllowMultipleAnswers
                    .QuestionNo = item.QuestionNo
                    .Required = item.Required
                    .TempAnswer = ls_prevAnswer
                End With


            If l_CurrentQuestion.AnswerType = constants.MULTIPLE_CHOICE Then
                'Get Choices
                Dim li_questionID As Integer = l_CurrentQuestion.ID
                If li_resultCount = 0 Then
                    l_Choices = db.Choices.SqlQuery("select * from Choices where ChildQuestionID = " & li_questionID & "").ToList
                    l_Choices = db.Choices.SqlQuery("select * from Choices where QuestionID = " & li_questionID & "").ToList
                End If
                Session("Choices") = l_Choices
            End If

            If Session("TotalQuestions") Is Nothing Then
                li_total_NoOfQuestion = db.Database.SqlQuery(Of Integer) _
                    ("select max(a.MaxOrder) from(select max(QuestionOrder) " &
                    "as MaxOrder from Questions union select QuestionOrder from " &
                Session("TotalQuestions") = li_total_NoOfQuestion
            End If

            With l_surveySession
                .QuestionCtr = li_questionCtr
            End With

            Session("SurveySession") = l_surveySession
            Session("CurrentQuestion") = l_CurrentQuestion
            Session("Back") = False
            Return l_CurrentQuestion
        Catch ex As Exception
            Call ExceptionHandler(ex)
        End Try
    End Function

And this is from the view:

@ModelType Survey_App.Models.CurrentItem
ViewData("Title") = "Index"
Layout = "~/Views/Shared/_Layout.vbhtml"
Dim l_choices = Session("Choices")
Dim l_activeSurvey = Session("ActiveSurvey")
Dim ls_tempAnsType As String = Model.AnswerType.ToString 'this is the line indicated in the error msg
Dim ls_temp As String = ""
Dim ls_tempAnswer() As String = Nothing

Dim li_totalQuestions As Integer = 0
li_totalQuestions = Session("TotalQuestions")
Dim ls_POSTAction As String = vbNullString

What I have tried:

The error appears some time (maybe 10-15 seconds) after going through the home page but not always immediately. I also tried some debugging and it looks like the session variables also return nothing after that some time.
Sandeep Mewara 25-Apr-22 4:41am
Based on screenshot, it's a NRE. You should be able to put breakpoint see exactly which object is NULL and then handle it.
Member 14931933 25-Apr-22 4:48am
I'm sorry but what is NRE? I have already tried putting a breakpoint and debugging and found out that all of the Session variables have null values and even the webviewpage model returns a null value even though I already set the sessionState timeout to 900 seconds. And this only happens on the web server.
Richard Deeming 25-Apr-22 11:58am
NRE = NullReferenceException

Either Model is Nothing, or Model.AnswerType is nothing. You need to debug your code to find out which, and then work out why.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900