Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Stack Trace shows my development files path?

Visual Studio 2010 SP1, compiled WCF app, put it on a server, and of course it got an error on the first run (what's new), outputted Stack Trace to log file.

It's seeing the path to my development environment. Why? Is it because I deployed it as Debug compared to Release or is there something else, or shall I be more careful about outputting Stack Traces regardless?

04/09/2012 03:58:46: Error: Object reference not set to an instance of an object.    at App1.Logging.LogMessageToFile(String msg, Boolean isUsingClickOnceApp) in C:\Users\robcube\Documents\Visual Studio 2010\Projects\AppWebService\App1\Logging.cs:line 63    at App1.App1Main.ConnectWebService(String description) in C:\Users\robcube\Documents\Visual Studio 2010\Projects\AppWebService\App1\International.cs:line 40 04/09/2012 03:58:46: Error: Object reference not set to an instance of an object.    at App1.App1Main.UpdateActivityLog(String data, String userName, Boolean deleteData, Int64 firstId, Int64 lastId, String changeType) in C:\Users\robcube\Documents\Visual Studio 2010\Projects\AppWebService\App1\App1Main.cs:line 641 

Thanks, -rob

like image 527
Robert Koch Avatar asked Sep 05 '12 12:09

Robert Koch


People also ask

What does a stack trace show?

A stack trace shows the call stack (sets of active stack frames) and provides information on the methods that your code called. Usually, a stack trace is shown when an Exception is not handled correctly in code. (An exception is what a runtime environment uses to tell you that there's an error in your code.)

What are stack trace errors?

Stack trace error is a generic term frequently associated with long error messages. The stack trace information identifies where in the program the error occurs and is helpful to programmers. For users, the long stack track information may not be very useful for troubleshooting web errors.

Should stack traces be logged?

Therefore, you should log a stacktrace if, and only if, and always if, the exception indicates a bug in the program. However, that does not always indicate that a method you write should catch and log the exception.


1 Answers

It is because you copied the .pdb files as well as the executables. The CLR will look for them when it generates a stack trace to try to give as much info as possible about the stack frames in the trace. The .pdb stores the source file name and line number.

You are supposed to deploy the Release build of your code. That enables optimizations that can make your code run a lot faster. You can still copy the .pdb files for that build, they normally have that debug info stripped. Project + Properties, switch to the Release build, Build, Advanced, "Debug Info" setting. The normal setting here for release builds is "pdb-only" instead of "full". Which implies that source file and line number is not included. Which makes sense, stack traces tend to be a bit unreliable after the jitter has optimized the code.

like image 61
Hans Passant Avatar answered Sep 24 '22 09:09

Hans Passant