Results 1 to 6 of 6

Thread: [2005] New StackTrace

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Jacksonville, Florida
    Posts
    147

    Angry [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.
    vb.net and C# in 2008 .net 3.5
    ImaginaryDevelopment blog

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Re: [2005] New StackTrace

    What kind of error you are getting while running it from the publish install?
    Microsoft Techie

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Jacksonville, Florida
    Posts
    147

    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.
    vb.net and C# in 2008 .net 3.5
    ImaginaryDevelopment blog

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Jacksonville, Florida
    Posts
    147

    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?
    vb.net and C# in 2008 .net 3.5
    ImaginaryDevelopment blog

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width