473,938 Members | 5,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Diagnost ics.StackTrace is wrong sometims

I use System.Diagnost ics.StackTrace to get the stack trace of the
current function, to print out the function's name to the log, and
sometimes it shows that a function that doesn't even write to the log
is what is writing to the log. This just can't be, so
System.Diagnost ics.StackTrace must be returning the wrong information
(from another thread, i suppose).

Is this normal, or expected? Can it be reliable?

Zytan

Apr 25 '07
12 3869
Ah. Is it possible that the automatic function inlining built into C# is
causing your function to just "disappear" ? It won't show up in a stack
trace if it no longer exists.
I've just checked, and for that to happen, it needs to miss TWO
functions in the chain, but they ARE in the same call stack. And
these functions are not small functions! But, at least this explains
what is happening...

Unfortunately, it makes the call stack rather useless to determine
what the current function is...

Zytan

Apr 28 '07 #11
Can you post a short sample of code that displays a correct stack trace when
compiled as Debug and an incorrect stack trace when compiled as Release?
static void Main(string[] args)
{
MyFunc();
Console.ReadKey (false);
}

public static void MyFunc()
{
Console.WriteLi ne(Program.GetC allStack());
}

public static string GetCallStack()
{
System.Diagnost ics.StackTrace callStack = new
System.Diagnost ics.StackTrace( );
string s = "";
int index = 0;
while (true)
{
System.Diagnost ics.StackFrame frame =
callStack.GetFr ame(index);
if (frame == null) break;
System.Reflecti on.MethodBase method = frame.GetMethod ();

if (index 0) s = " --" + s;
s = method.Declarin gType.Name + "." + method.Name + "()" + s;
index++;
}
return (s);
}

Zytan

Apr 28 '07 #12
Ah. Is it possible that the automatic function inlining built into C# is
causing your function to just "disappear" ? It won't show up in a stack
trace if it no longer exists.
Pete, I think I solved the issue.

My functions were large, so they were NOT being deleted from the call
stack, but..... my WriteFunction() function which my function call is
tiny. AND, it has to take measures to not print ITSELF when its
caller is asking "who am I?". So, it counts to skip itself where it
expects to be in the call stack. In release mode, since it is so
small, it gets ejected from the call stack, and thus when it chooses
to skip itself, it's really skipping the function name that I wanted!
And, furthermore, because this WriteFunction() is a wrapper, and not
the real deal, they are likely BOTH ejected from the release call
stack, which explains why TWO of my treasured functions are missing
from the display!

NOW, for the solution to this mess...

Zytan

Apr 28 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
322
by: Raj Dhrolia | last post by:
Hi, In one of my method, I want to know the class/function that called/invoked this method. i.e. i have a function named Method1() in class1. I want "ClassX.MethodX()" in Method1(), when MethodX() of ClassX invokes Method1() function I think System.Reflection might provide some help. Regards.
1
5497
by: ginee lee via .NET 247 | last post by:
(Type your message here) hi all, It seems that the arguments of System.Diagnostics.Process.Start()can only be the absolute path. The args can not be like".\abc\efg.exe" or "..\abc\efg.exe". While i use relative path,the function doesn't work. Any solution?? The other question is... i take a example fisrt! System.Diagnostics.Process.Start("c:\\abc.exe", "hello.txt"); itworks fine. BUT if the second arg replace with "helloworld.exe",...
5
4048
by: David Conorozzo | last post by:
I am able to create new sources using CreateEventSource. I can call GetEventLogs, I can delete sources, I can see if sources exist BUT, as soon as I try a "WriteEntry", I get an exception: {System.InvalidOperationException} : {System.InvalidOperationException} HelpLink: Nothing InnerException: {System.ComponentModel.Win32Exception}
4
15685
by: Jiho Han | last post by:
I have the following defined in web.config under <configuration> node: <system.diagnostics> <switches> <add name="MainSwitch" value="4"/> </switches>
1
15999
by: martin | last post by:
Hi, I'm having some problems with the System.Diagnostics.EventLog class in .NET 2.0 I need to recreate an event message source inside a new log but the messages keeps ending up in the old log?! I have simplified my code into this tiny snippet: EventLog.CreateEventSource("mySrc", "myLog1");
4
5387
by: Ben | last post by:
Hello everybody I got confused by this problem for which I don't have a logical explanation. There is a Thread (ThreadA) which receives Events from another system thread (ThreadS). ThreadA then adds a time stamp to the received event and adds it to a event queue. This works well (therfore not shown here). The queue fills up. Then I used a timer to check every millisecond for new events in the queue and send it to another thread...
1
2552
by: dwcscreenwriterextremesupreme | last post by:
I am trying to automate a mysqldump backup through C# and for some reason the System.Diagnostics.Process is just not working as expected for me. What I want is for the following code to start a mysqldump, wait there until it finishes, and then continue the loop. foreach (DataRow dataRow in backupdt.Rows) { System.Diagnostics.Process proc = new
6
10551
by: kimiraikkonen | last post by:
Hello, I want to ask this: If i do: System.Diagnostics.Process.Start("c:\lame", "--preset standard c:\blabla.wav c:\blabla.mp3") it works. But i don't want this. I want my 2 textboxes must take place as variable like: System.Diagnostics.Process.Start("c:\lame", "--preset standard textbox1" textbox1.text + textbox2.text). But that doesn't work. Meanwhile textboxes are the
7
15862
rhitam30111985
by: rhitam30111985 | last post by:
Hi all i am trying to compile a set of source files located in location In the following code sample i am trying to compile a visual c++ 6.0 (dsp) project from a c# application ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", @"/c set path=%programfiles%\Microsoft Visual Studio\Common\MSDev98\Bin"); procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute =...
0
9962
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11089
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9850
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8207
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7377
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6072
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4441
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3495
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.