locked
StackTrace optimization in c#.net

    Question

  • 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

            {

              set

                {

                 _strErrorMessage = "Error : " + value;

                 //Call the method to log error.

                 LogError(value);

     

                }

            }

    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.

    MethodA()

     {

       Logger obj=new Logger();

     

       obj.ErrorMessage="Failure";

    }

    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

Answers

  • 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".
    • Proposed as answer by FUCK QHR Wednesday, April 13, 2011 5:02 AM
    • Marked as answer by Lie YouModerator Monday, April 18, 2011 1:51 AM
    Monday, April 11, 2011 9:59 AM