473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get line number from exception stack trace

Hi there,

The .pdb files are generally not installed in a production environment.
As a result, when an exception occurs, the runtime can't resolve the
lines of the code where the problem happened. Instead, one gets the
offsets, e.g.:

[NullReferenceException: Object reference not set to an instance of an
object.]
MyClass.DoSomething(String s) +554

If I haven't changed the source code on my development machine, is
there any way to translate the offset (+554) into the line number?

I tried using ILDASM and looking at the IL but couldn't find anything
that would correspond to offset +554. ILDASM showed the method has
offsets from IL_0000 to IL_00bc

Thanks,

-Oleg.

May 19 '06 #1
1 5774
Ol*********@gmail.com wrote:
The .pdb files are generally not installed in a production environment.
This is safe to do, by the way. You can build PDBs for your release
build, and you'll get line number information. Mind that generating the
string which includes the stack trace will be more expensive, though,
because the pdb will be opened up and searched.
I tried using ILDASM and looking at the IL but couldn't find anything
that would correspond to offset +554. ILDASM showed the method has
offsets from IL_0000 to IL_00bc


The offset will probably be in the machine code generated from the MSIL.
You could try debugging the release build in Mixed mode (with "Unmanaged
debugging" turned on) and putting a breakpoint inside the method. By
switching to the CPU view you'll be able to see what happened at that
offset, after you convert it to hex.

-- Barry

--
http://barrkel.blogspot.com/
May 19 '06 #2

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

Similar topics

4
by: Barry Mossman | last post by:
Hi, I am throwing an exception derived from ApplicationException as follows catch (Exception ex) { throw new MyException("message", ex); } My exception's constructor is: public...
4
by: .Net Sports | last post by:
I'm getting a "Specified cast is not valid" error that does not point to the line with the code in error, but instead :An unhandled exception was generated during the execution of the current web...
0
by: Me | last post by:
I am writing a web application and I want to catch and rethrow every unhandled exception to the Application_Error. However, the line number indicated in the stack trace is from the Throw line,...
2
by: Chris Stiefeling | last post by:
Hi, I am experiencing a strange problem. I am reading and writing xml files via XmlDocument and XmlTextWriter. In the debugger everything works fine but outside the debugger (debug or release)...
6
by: Rotsey | last post by:
Hi, Am trying to be able to the line number of an exception. The stack trace is not showing it. rotsey
2
by: pavel.orehov | last post by:
Hi, I am using Environment.StackTrace to print the stack trace to the log when I have any exceptions in my application. When I work in development environment I see the line numbers in the...
2
by: John | last post by:
Hi For error logging purpose, is it possible to get from the vb system feature the SUB name and the line number? Thanks Regards
4
by: Jeff Jarrell | last post by:
I have a block of code that during development is prone to casting errors. It is mostly a DataReader type thing. It looks something like this. _prtPNID = myDLReader.GetString("prtPNID")...
5
by: IdleBrain | last post by:
I am trying to log the Application name, Method name, line number and column number whenever an exception is generated in an C# 2005 application using the following code. Problem is that the...
2
by: =?Utf-8?B?QXJ0aHVyIFBhcmtlcg==?= | last post by:
I've been having a problem occasionally with exceptions having the wrong line number listed. The situation is this: I have a function with a try-catch, and in the catch it logs the message and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.