StackTrace optimization in c#.net


  • hi all,

             In my c#.net application i have used stacktrace to capture method name and file name in case of failure.

    There is some difference in the stacktrace between x86 and x64 platform.

     public string ErrorMessage




                 _strErrorMessage = "Error : " + value;

                 //Call the method to log error.





    In the above code snippet, while setting the ErrorMesasage property i am calling LogError method which is capturing the stack trace and writing it into the logfile.



       Logger obj=new Logger();




    In this case in X86 platform the stack trace is containing two stackframes. one for methodA and another for setter of ErrorMessage Property.

    In X64 platform, the stack trace is containing only one stackframe for methodA and there is no stackframe for setter of ErrorMessage Property.

    can anybody explain me how the optimization is happening while getting the stacktrace?

    Monday, April 11, 2011 7:47 AM


  • Hi,

    Or could it be just that the method is inlined rather than some kind of "stacktrace optimization" ? What if you try the noinlining flag ? (http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimploptions.aspx)

    Also not sure how you get the stack trace but if this is for exceptions (is this what you meant with "failures" ?), my personal preference would be to get the stack trace for the exception object being processed rather than the stacktrace for the method that processes this exception.

    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Monday, April 11, 2011 9:59 AM