|
-
Dec 18th, 2008, 12:42 PM
#1
Thread Starter
Addicted Member
[2005] New StackTrace
Code:
Private Sub TestMethodNameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestMethodNameToolStripMenuItem.Click
ShowMyName()
End Sub
Private Sub ShowMyName()
Dim StackInfo As New StackTrace
MsgBox("StackCount=" + StackInfo.FrameCount.ToString)
MsgBox(StackInfo.GetFrame(0).GetMethod.Name)
End Sub
When the msgbox that gets the framecount is included on a publish, I get what i want a msgbox("ShowMyName") when it is not I get "TestMethodNameToolStripMenuItem_Click".
When I run in the debugger it always works properly "ShowMyName". When I run it straight from my debug folder it works properly. When I run it from the publish install... it's wrong.
-
Dec 19th, 2008, 04:25 AM
#2
Fanatic Member
Re: [2005] New StackTrace
What kind of error you are getting while running it from the publish install?
-
Dec 19th, 2008, 04:34 AM
#3
Re: [2005] New StackTrace
This is directly from the dcoumentation for the StackTrace class:
StackTrace might not report as many method calls as expected, due to code transformations that occur during optimization.
Presumably, because you are doing nothing other than calling ShowMyName from TestMethodNameToolStripMenuItem_Click the compiler is optimising your code by removing the ShowMyName method altogether and putting the code it contains into the TestMethodNameToolStripMenuItem_Click method instead, to save the extra method call. Optimisations are enabled for a Release build by default and not for a Debug build, hence the difference between them. Presumably adding the extra line makes enough difference that the compiler isn't able to, or chooses not to, optimise the code by removing the ShowMyName method.
This is another fine example why everyone should follow my rule: READ THE DOCUMENTATION FIRST.
-
Dec 19th, 2008, 09:04 AM
#4
Thread Starter
Addicted Member
Re: [2005] New StackTrace
The 'release' build doesn't have this problem either btw, just the published. So unless they mean publish when they say release (in the release folder) then the documentation would not be helpful. And loading the same number of frames... which I noticed 27 in non-debug (release and publish) vs 36 in debug, is the same in release vs publish.
-
Dec 19th, 2008, 11:45 AM
#5
Thread Starter
Addicted Member
Re: [2005] New StackTrace
is there a more reliable way to get the name of the executing method? or the method that called that method?
-
Dec 19th, 2008, 07:59 PM
#6
Re: [2005] New StackTrace
The way you're doing it is completely reliable. If a method doesn't exist in your compiled code then it won't be reported. You can always turn optimisations off for your Release configuration and try again, then you should find that you get the results you expect but your application will not be as efficient as it could be.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|