Felecha Posted December 3, 2004 Posted December 3, 2004 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? Quote
Administrators PlausiblyDamp Posted December 3, 2004 Administrators Posted December 3, 2004 IIRC you will get null returned if it cannot determine the filename - does the customer's pc also have the debug symbols (.pdb) for your app? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.