473,396 Members | 2,018 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.

Line No

Hi,
How to Get a Line Number in C-Sharp? For Loging purpose , i want to log
the Line no where the Error Happens?

Regards,
R.Baskar
Nov 15 '05 #1
10 2155
You do realize that the executing code looks nothing like the code you
write in an editor? Once the JIT has worked it's magic, full of optimizations
and rewrites, in-lining etc you will be executing native win32 code.

--
ANDREAS HĹKANSSON
STUDENT OF SOFTWARE ENGINEERING
andreas (at) selfinflicted.org
"Baskar RajaSekharan" <rb*@srasys.co.in> wrote in message news:#J**************@TK2MSFTNGP09.phx.gbl...
Hi,
How to Get a Line Number in C-Sharp? For Loging purpose , i want to log
the Line no where the Error Happens?

Regards,
R.Baskar
Nov 15 '05 #2
Baskar RajaSekharan wrote:
How to Get a Line Number in C-Sharp? For Loging purpose , i want to
log
the Line no where the Error Happens?


There is no solution for Release-Builds.

For Debug Builds you can use the StackFrame-Class like the following:

<code>
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(true);
MessageBox.Show(sf.ToString());
// or sf.GetFileLineNumber();
</code>
Release-Builds are not supporting line infos at runtime.

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Nov 15 '05 #3
Please, don't use html formatting in news groups

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
If you do provide the PDB file together with your release file, Line Info
are supported.
In fact, such information is not dependant of Debug/Release build. They are
contained in the PDB.
PDB is generated by default only in Debug mode.

José

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn********************************@127.0.0.1. ..
Baskar RajaSekharan wrote:
How to Get a Line Number in C-Sharp? For Loging purpose , i want to
log
the Line no where the Error Happens?
There is no solution for Release-Builds.

For Debug Builds you can use the StackFrame-Class like the following:

<code>
System.Diagnostics.StackFrame sf = new

System.Diagnostics.StackFrame(true); MessageBox.Show(sf.ToString());
// or sf.GetFileLineNumber();
</code>
Release-Builds are not supporting line infos at runtime.

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Nov 15 '05 #5
José Joye wrote:
If you do provide the PDB file together with your release file, Line
Info are supported.


You cannot generate a "Release" version with PDB-Infos!!!! This is at least
not possible with Visual-Studio.
The only thing you can do is switch on the "Generate Debug Info" entry; but
then you DO NOT HAVE A REALSE version anymore!!!
A special attribute is placed into the assembly that the JIT compiler does
NOT OPTIMIZE the code!!! So you cannot make a release version with PDB-files!

Greetings
Jochen

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Nov 15 '05 #6
Yes it is!

I did it with all my assemblies that are in production and I do get the line
#.
- Go under property for your project
- Under Configuration Property, choose Build
- Under Outputs, Set "Generate Debugging Information" to TRUE

José

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@127.0.0.1 ...
José Joye wrote:
If you do provide the PDB file together with your release file, Line
Info are supported.
You cannot generate a "Release" version with PDB-Infos!!!! This is at

least not possible with Visual-Studio.
The only thing you can do is switch on the "Generate Debug Info" entry; but then you DO NOT HAVE A REALSE version anymore!!!
A special attribute is placed into the assembly that the JIT compiler does
NOT OPTIMIZE the code!!! So you cannot make a release version with PDB-files!
Greetings
Jochen

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Nov 15 '05 #7

"Andreas Hĺkansson" <andreas (at) selfinflicted.org> wrote in message news:Oc**************@TK2MSFTNGP09.phx.gbl...
You do realize that the executing code looks nothing like the code you
write in an editor? Once the JIT has worked it's magic, full of optimizations
and rewrites, in-lining etc you will be executing native win32 code.

Yes, but many compilers have macros that will automatically expand to give the file name and the line number where they were encountered during compilation. This enables you to include that information in your output when you're reporting an error. I haven't found the way to do this in C# yet.
Nov 15 '05 #8
José Joye wrote:
You cannot generate a "Release" version with PDB-Infos!!!! This is at
least not possible with Visual-Studio.


Yes it is!

I did it with all my assemblies that are in production and I do get
the line #.

- Go under property for your project
- Under Configuration Property, choose Build
- Under Outputs, Set "Generate Debugging Information" to TRUE


Sorry to correct you, but if you enable this option,
then you HAVE A DEBUG VERSION!

Look into the assembly (maybe with ILDASM) and you will see that this
assembly contains a DebuggableAttribute.

And now take a look at the doc for this attribute and you will see that if
this attribute is present the JIT compiler will not optimize your code!
It will just do a "simple" JIT compiling!

And this is the only difference between an debug and release version!!!
So you have a debug version!

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Nov 15 '05 #9
Hi,

Thanks for your information. Howerver, this is still not clear to me:

1)
Assuming you are correct, what is the purpose of the property "Optimize
Code" (set to True in Release and to False in Debug)?

2)
I could not imagine that such important features (line# and some other vital
information that can be got from StackTrace()) are simply not available in
Release mode. How could you give support to your customer without them?

José

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@127.0.0.1 ...
José Joye wrote:
You cannot generate a "Release" version with PDB-Infos!!!! This is at
least not possible with Visual-Studio.


Yes it is!

I did it with all my assemblies that are in production and I do get
the line #.

- Go under property for your project
- Under Configuration Property, choose Build
- Under Outputs, Set "Generate Debugging Information" to TRUE


Sorry to correct you, but if you enable this option,
then you HAVE A DEBUG VERSION!

Look into the assembly (maybe with ILDASM) and you will see that this
assembly contains a DebuggableAttribute.

And now take a look at the doc for this attribute and you will see that if
this attribute is present the JIT compiler will not optimize your code!
It will just do a "simple" JIT compiling!

And this is the only difference between an debug and release version!!!
So you have a debug version!

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Nov 15 '05 #10
José Joye wrote:
Thanks for your information. Howerver, this is still not clear to me:

1)
Assuming you are correct, what is the purpose of the property
"Optimize Code" (set to True in Release and to False in Debug)?

The main problem is the VS-IDE. It only allows to select either
"Generate Debuggin Information" to true or false. True means "/debug" and
false does not add any switch.

But the "C# compiler" doc also knows "/debug:pdbonly" which is between this
two variants.

If you specify "/o" and "/debug:pdbonly", then the DebugableAttribute is
NOT put into the assembly!
But with VS-IDE you cannot make this!

One problem still exists:
If you generate an assembly with this two switches, you are still not able
to get line infos from the "StackFrame" class.

Maybe you will get some info from the sos-ext to windbg... but for this
your need the WHOLE memory dump!!!
2)
I could not imagine that such important features (line# and some other
vital information that can be got from StackTrace()) are simply not
available in Release mode. How could you give support to your customer
without them?


This is also my main problem!
With unmanaged C++ you can write an small MiniDump and you will have all
infos you need (incl. line infos if you have the correct PDB file)


It would be great if someone from Microsoft could give some answers...


--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Nov 15 '05 #11

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

Similar topics

8
by: Peter A. Schott | last post by:
Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
14
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
11
by: xdevel | last post by:
Hi, I don't understand option. if I write: #line 100 "file" I change file numeration to start to line 100 but what "file" ? any example?
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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...
0
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...

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.