Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting line number of exception in dot net app

Tags:

.net

I have got a data migration app writting in .Net 3.0 VS2008.

I have deployed in debug mode and copied the PDB file to the server I want to runit.

I get an exception but no line number.

This is how i display the exception

Why is there no line number of the exception???

Malcolm

       string msg = string.Format("{0} {1} {2}",ex.Message,ex.StackTrace.ToString(),ex.Source.ToString());               
        if(ex.InnerException != null)
            msg += string.Format(" {0}", ex.InnerException.ToString());
        return msg;
like image 317
Malcolm Avatar asked Dec 22 '22 11:12

Malcolm


2 Answers

If you aren't getting line numbers, then either

a) The .NET runtime is determining that the .pdb doesn't match the assembly (out of date, compiled with optimizations, etc.)

or

b) The assembly is running from a directory that's different from the one containing the .pdb (a Windows service, for example, runs under %WINDOWS%\System32)

It doesn't sound like the first possibility applies to you, so is this a Windows service or is the execution directory being changed?

In any event, you should be able to use the AppDomain.CurrentDomain.BaseDirectory property to determine where assemblies and .pdb's would be searched for (by the default, this can be overridden but should be a good indicator if it's being changed)

like image 106
Adam Robinson Avatar answered Jan 12 '23 15:01

Adam Robinson


dont mess with the exception string... trying to pretty it up, just ex.toString() on it to get the stack to unwind and print the info you are looking for

Of course the pdb files need to be there for the debug info. but formatting the exception is completely unnecessary just call ex.toString() and it formats it for you.

like image 21
Chad Grant Avatar answered Jan 12 '23 15:01

Chad Grant