473,830 Members | 1,989 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 #1
12 3854
I doubt it. What's more than likely is you are not synchronizing access
to the log, so you are writing stack traces that are intermingled with each
other.

What you need to do is synchronize access to the log file, writing out
the stack traces, or, have some sort of correlation id associated with each
stack trace that you write, which will allow you to group all the
information later.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Zytan" <zy**********@g mail.comwrote in message
news:11******** **************@ b40g2000prd.goo glegroups.com.. .
>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 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
I doubt it. What's more than likely is you are not synchronizing
access to the log, so you are writing stack traces that are intermingled
with each other.
I doubt that the StackTrace is wrong too. However, Zytan's point is that
function names wind up in the log that should *never* be in the log. It's
not that they're in the wrong order. It's that they should just never
appear at all.

For that, I have no explanation.

Zytan, if you can provide a concise example of code that reliably reproduces
the problem, that would be helpful.

Pete

Apr 25 '07 #3
I doubt it. What's more than likely is you are not synchronizing access
to the log, so you are writing stack traces that are intermingled with each
other.
That is likely. I am using TextWriter, which is synchronized, but if
I make two calls to my LogWrite function, then they could get mixed
up. The problem is that I can see when such a thing happens, and my
issues occur so often, it must be something else. Although, your
point is taken, and I'll solve this issue ANYWAY, even though it
hardly happens, to remove that as a possibility.

I'll reply to Peter's post with what I think is the real issue...

thanks,
Zytan

Apr 26 '07 #4
I doubt that the StackTrace is wrong too.

I know, how can it be wrong, when so many people use it?
However, Zytan's point is that
function names wind up in the log that should *never* be in the log. It's
not that they're in the wrong order. It's that they should just never
appear at all.

For that, I have no explanation.
I have narrowed the issue down:

It works perfectly, always, in debug mode.
It doesn't work, in release mode.

I MAY have deleted the .pdb files from the release mode directory for
EACH time this issue occurred. Would that cause this to happen?
Would it be left to guess (incorrectly) without the PDB?

Zytan

Apr 26 '07 #5
Since I cannot see my own post yet, due to Google Groups being REALLY
slow the past 2 days, I will append here:

I have the PDB file in the release directory of my program, and the
bug still occurs. So, the presence or lack of the PDB file is not
what is causing this.

I'll try and make a small program that shows the error, and maybe I'll
solve this myself in the process.

Zytan

Apr 26 '07 #6
System.Diagnost ics.StackTrace callStack = new
System.Diagnost ics.StackTrace( );

returns different information whether you're in debug or release mode.

Zytan

Apr 26 '07 #7
(I still cannot see any additional posts to this thread, including my
own so I'll post my results here)

I have a GetCallStack() function that just calls:
x = new System.Diagnost ics.StackTrace( );
and extracts the stack from x, and returns it as a string.

When I call this from Main(), I get:

// DEBUG: ThreadHelper.Th readStart() --ExecutionContex t.Run() -->
ThreadHelper.Th readStart_Conte xt() --HostProc.RunUse rsAssembly() -->
AppDomain.Execu teAssembly() --AppDomain.nExec uteAssembly() -->
Program.Main() --Program.GetCall Stack()
// RELEASE: Program.Main() --Program.GetCall Stack()

Note the last two in the stack are similar.
But, when I call this function from inside a class function, that
Main() calls:

// DEBUG: ThreadHelper.Th readStart() --ExecutionContex t.Run() -->
ThreadHelper.Th readStart_Conte xt() --HostProc.RunUse rsAssembly() -->
AppDomain.Execu teAssembly() --AppDomain.nExec uteAssembly() -->
Program.Main() --MyClass.MyFunc( ) --Program.GetCall Stack()
// RELEASE: Program.Main() --Program.GetCall Stack()

Note the last 2/3 of each one is different. MyClass.MyFunc( ) is no
where to be found in the release build!!!

Zytan

Apr 26 '07 #8
"Zytan" <zy**********@g mail.comwrote in message
news:11******** *************@n 35g2000prd.goog legroups.com...
[...]
It works perfectly, always, in debug mode.
It doesn't work, in release mode.

I MAY have deleted the .pdb files from the release mode directory for
EACH time this issue occurred. Would that cause this to happen?
Would it be left to guess (incorrectly) without the PDB?
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?

Pete

Apr 26 '07 #9
"Zytan" <zy**********@g mail.comwrote in message
news:11******** **************@ r35g2000prh.goo glegroups.com.. .
[...]
Note the last two in the stack are similar.
But, when I call this function from inside a class function, that
Main() calls:

// DEBUG: ThreadHelper.Th readStart() --ExecutionContex t.Run() -->
ThreadHelper.Th readStart_Conte xt() --HostProc.RunUse rsAssembly() -->
AppDomain.Execu teAssembly() --AppDomain.nExec uteAssembly() -->
Program.Main() --MyClass.MyFunc( ) --Program.GetCall Stack()
// RELEASE: Program.Main() --Program.GetCall Stack()

Note the last 2/3 of each one is different. MyClass.MyFunc( ) is no
where to be found in the release build!!!
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

Apr 26 '07 #10

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
5492
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
4040
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
15654
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
15992
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
5380
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
2546
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
10544
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
15848
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
9780
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10476
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...
1
10520
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10196
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9310
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
7739
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
6940
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
5615
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...
3
3070
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.