0

I have an issue I am unable to replicate in either my local environment or my UAT environment. It only seems to be an issue with production.

I've inherited this project and cannot seek the original developers, so many things about the project I have to figure out myself.

About 95% of all code is surrounded by try/catch blocks to catch errors that seem to happen no matter what goes on. However inside all the catches there is a little bit of logging going on. This is the final bit that happens in the base master page:

Public Property HandelException() As Exception
        Get
            Return _Exception
        End Get
        Set(ByVal value As Exception)
            If value IsNot Nothing Then
                _Exception = value
                Dim _TempExceptionLog As New TempFramework.FMKExceptionLog()
                _TempExceptionLog.WriteException(HandelException)
                _logger.Error(_Exception)
                SetMessage(_Exception.Message)
            End If
        End Set
    End Property

In this case, _logger is declared as:

Private ReadOnly _logger =    LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName)

_TempExceptionLog is writing the log to the database while _logger is using log4net, but there are no configurations in the webconfig for any of my dev platforms.

SetMessage is used to manipulate a label on the page with the appropriate error message.

The stack trace I'm getting every now and then on the server is:

Exception information: 
    Exception type: NullReferenceException 
    Exception message: Object reference not set to an instance of an object. 

 Stack trace:    at TempWebControl.TempWCBase.TempWCMaster.set_HandelException(Exception value)
   at TempWebControl.WCBase.TempWCPage.set_HandelException(Exception value)
   at Reservations_Reservations.FillCarMake() in     C:\BuildMaster\_SVCTMP\_A4\SRC\PublicSite\TempName\Reservations\Reservations.aspx.vb:line 5983
   at Reservations_Reservations.FillInformation() in C:\BuildMaster\_SVCTMP\_A4\SRC\PublicSite\TempName\Reservations\Reservations.aspx.vb:line 5896
   at Reservations_Reservations.Page_Load(Object sender, EventArgs e) in C:\BuildMaster\_SVCTMP\_A4\SRC\PublicSite\TempName\Reservations\Reservations.aspx.vb:line 239
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

It looks like the Null reference exception is coming from this setter, am I wrong in this assumption? If so what could be going on.

3
  • Almost all cases of NullReferenceException are the same. Please see "What is a NullReferenceException in .NET?" for some hints. Commented Feb 4, 2014 at 22:20
  • That presents a very basic explanation of NullReferenceExceptions. While I am greatful for your response I am well aware of what causes a null reference exception and am looking for guidance on how to approach my current problem seeing as though the code works in my dev environment but is throwing this null reference exception in a different environment. Commented Feb 4, 2014 at 22:31
  • If you were to read more of that post, you'll find it goes well beyond a basic explanation. Some of the examples in there might help jog your thought process. Not that it matters in this case - I see only one thing that could easily be null. Commented Feb 4, 2014 at 23:04

1 Answer 1

1

From looking at your code, it's clear that _logger is null.

Sign up to request clarification or add additional context in comments.

2 Comments

That's what I think, but _logger is not null every time and the error is only appearing a fraction of the times. Having never had used log4net, I'm not sure if it is ever null from get LogManager.GetLogger()
Try checking for null explicitly and throwing an explicit exception, like throw new InvalidOperationException("_logger is null!!!");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.