views:

3422

answers:

7

Is there a way to display the lines in the stack trace for the .NET assembly build/deployed in Release mode?

UPDATE:

My application is divided into three class library projects and one ASP.NET "website" project. The error I am trying to track down is in one of the three class library projects. I only deployed the pdb file for the class library project that is generating the "Object reference not set to an instance of an object" error.

The line numbers are still not showing up in the stack trace. Do I need to deploy the pdb files for all projects to get the line numbers in the stack trace?

Working solution

Deploying the pdb file for each application fixed the line number issue.

+1  A: 

Include debug symbols with your build/deployment package.

Ken Browning
where do I set that in Visual Studio 2008?
Michael Kniskern
+16  A: 
  • Go into the Properties window for the project where you want to see stack trace line numbers.
  • Click on the Build "vertical tab".
  • Select "Release" configuration. Check the DEBUG constant parameter.
  • Uncheck the "Optimize code" parameter to avoid the occasional trace issue with inlined code (this step is not essential).
  • Press the Advanced... button and choose Output -> Debug Info -> pdb-only.
  • Deploy the generated .pdb file with the assembly.
Coxy
Do I have to deploy the pdb file along with the assembly?
Michael Kniskern
Yes. That's where the debug symbols and line numbers are at.
John Saunders
You probably don't want to expose this information if you don't have to. Use it to debug a clients problem, yes. But you don't always want to do it because debugging information can give away sensitive data and be an attack vector. Depending on what your app is.
jeffamaphone
@jeffamaphone - I am only doing this to debug a pesky "Object reference not set to an instance of an object" error that only occurs in production. The methods it occurs is quite large and it could be any number of items. This will hopefully help with pinpointing the problem.
Michael Kniskern
@jeffamaphone (cont.) - it will be removed once we have resolved it.
Michael Kniskern
Is there any way to do this when installing dlls in the GAC?
Jonathan Parker
@coxymla: I tried getting the method name, file name and line number without unchecking "optimize code", and without changing the Debug Info (it was in "full" by default). Do you know why it still works?
Carlo
@Carlo - not 100% sure from what you've posted. You do or you don't get line numbers? Anyway, I recommend asking a new question for your particular situation.
Coxy
@Carlo: Debug information works with release (optimized) code as well, however debugging is somewhat limited (http://stackoverflow.com/questions/113866). However callstacks are quite reliable even in optimized code, with exception of inlined functions and ocasional situations where tail call can be missing because call xxx / ret sequence was replaced with jmp xxx.
Suma
+1  A: 

In VS 2008 Express, I found it under Project Properties --> Compile --> Advanced Compile Options.

Darel
A: 

n VS 2008 Express, I found it under Project Properties --> Compile --> Advanced Compile Options.

¿Where is that option?, i cant find that

juan carlos
+1  A: 

My solution

Copy pdb file in same folder that executable file.

now i can view the line number when run the exe file.

this is reason

http://msdn.microsoft.com/en-us/library/bb694540%28VS.85%29.aspx

juan carlos
+1  A: 

I've run into problems in the past where I feel the need to deploy PDB files with a release build in order to track down an error. The reason is, like you said, was that the exception occurred in a method that was very large and I could not accurately pinpoint where it was happening.

This might be an indication that the method needs to be refactored into smaller, more granular methods. Not a one size fits all answer, but this approach has served me well in the short term (I've often found the bug during the refactoring) and in the long run.

Just a thought.

slolife
A: 

How to deploy pdb file with msi? how to set that up for the setup project?

bsobaid