Archive for October 2nd, 2007|Daily archive page

StackTrace in .net difference for Debug and Release compilation modes

Today I’ve tried to build new version of our DataLayer – Diego. Unsuccessfully L But I have discovered some interesting stuff around StackFrames in .net I’ve build sample project. In debug mode .net gives access to full stack trace. And in release mode we have just information about method that makes call and called method. There is test project to check it :

using System;

using System.Collections.Generic;

using System.Text;

using System.Diagnostics;

using System.Reflection;

namespace Tester

{


class Program

{


static void Main(string[] args)

{
Child r = new
Child();

r.runit(“hello”, 4);

}

}


class
Base

{


public
void Execute()

{


StackTrace trace = new
StackTrace();


StackFrame[] frames = trace.GetFrames();


Console.WriteLine(“Frames count : {0}”, trace.FrameCount);


foreach (StackFrame frame in frames)

{

processFrame(frame);

}

}


private
void processFrame(StackFrame frame)

{


MethodBase method = frame.GetMethod();


ParameterInfo[] parameters = method.GetParameters();


Console.WriteLine();


Console.WriteLine(“\tMethod name:\t{0}”, method.Name);


foreach (ParameterInfo param in parameters)

{


Console.WriteLine(“\tParameter name : \t{0}”, param.Name);

}

}

}


class
Child : Base

{


public
void runit(string name, int count)

{

Execute();

}

}

}

And there we have result for Debug mode:

Frames count : 3

Method name: Execute

Method name: runit

Parameter name : name

Parameter name : count

Method name: Main

Parameter name : args

Results for Release mode:

Frames count : 2

Method name: Execute

Method name: Main

Parameter name : args