Jump to content
Xtreme .Net Talk

Same code, one machine throws Exception, other does not


Recommended Posts

Posted

Some time ago I wrote a little method to help with Exception handling, that uses the StackTrace and StackFrame classes to get the file name, method name, and line number where an Exception was actually thrown. I add that to my logging, very useful. This is the basic idea (I have a number of them, customized to Exception type)

 

Private Sub WriteToLog(ByVal ex As Exception)

Dim Trace As New StackTrace(ex, True)

Dim Frame As StackFrame = Trace.GetFrame(Trace .FrameCount - 1)

Dim FileNameParts() As String = Frame.GetFileName.Split("\")

Dim FileNameWithExtension As String = FileNameParts(FileNameParts.Length - 1)

Dim FileName As String = FileNameWithExtension.Substring(0, FileNameWithExtension.IndexOf("."))

Dim Method as String = Frame.GetMethod.Name

Dim LineNumber as Integer = Frame.GetFileLineNumber.ToString

etc.

 

Then I can write to my log, telling me all I want to know.

 

Today I discovered that one of our machines out at a customer site, just installed, is throwing an Exception in the above code. The String returned by StackFrame.GetFileName is null, and I get "Object reference not set to an instance of an object".

 

But the exact same code runs fine on my office development machine. They are identical boxes, Dell Dimension 8300, identical application running. Both have the latest .Net framework, both are Windows XP SP2. There is no exception for GetMethod or GetFileLineNumber. Just for GetFileName. And again, only one one box, not the other.

 

This is a complete mystery to me. Any ideas?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...