Malcolm
Malcolm

Reputation: 12864

Not getting line number of exception in dot net app

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;

Upvotes: 4

Views: 1649

Answers (2)

Chad Grant
Chad Grant

Reputation: 45382

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.

Upvotes: 1

Adam Robinson
Adam Robinson

Reputation: 185643

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)

Upvotes: 10

Related Questions