Line No

  • Thread starter Thread starter Baskar RajaSekharan
  • Start date Start date
B

Baskar RajaSekharan

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
 
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
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
 
Baskar said:
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
 
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é
 
José Joye said:
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
 
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é
 
"Andreas Håkansson" <andreas (at) selfinflicted.org> wrote in message 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.
 
José Joye said:
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
 
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é
 
José Joye said:
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
 
Back
Top