locked
handling exceptions stacktrace line number 0 RRS feed

  • Question

  • I want to get the line and filename where the exception is fired so I wrote :

    try{

    code

    }

    catch(Exceptionex)

                    {

    varst = newStackTrace(ex,true);

    // Get the top stack frame


    varframe = st.GetFrame(st.FrameCount - 1);

    // Get the line number from the stack frame


    varline = frame.GetFileLineNumber();

       }

    }

    What I get is {namefunction at offset 11364 in file:line:column <filename unknown>:0:0



    • Edited by Firas16 Tuesday, March 3, 2015 4:32 PM
    Tuesday, March 3, 2015 4:31 PM

All replies

  • HI Firas,

    Generally I use C# code snippet below to get file name and line number from Exception:

    StackTrace trace = new StackTrace(exception, true);
    string fileName = trace.GetFrame(0).GetFileName();
    int lineNo = trace.GetFrame(0).GetFileLineNumber();

    Hope it helps.

    Best regards,

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 5, 2015 6:14 AM
  • Hi Angie,

    It didn't work. I got the same result : filename = null and line number = 0.

    I don't know if it's related or not but when in the exceptions section in visual studio I add Common language runtime exceptions I have some exceptions fired when I run my solution. I have some pdb files missed as Microsoft.lightswitch.server.pdb.

    Thanks

    Firas

    Thursday, March 5, 2015 9:07 AM
  • It didn't work. I got the same result : filename = null and line number = 0.

    I don't know if it's related or not but when in the exceptions section in visual studio I add Common language runtime exceptions I have some exceptions fired when I run my solution. I have some pdb files missed as Microsoft.lightswitch.server.pdb.

    Correct.

    As discussed in this thread, first ensure that the appropriate ".pdb" files are alongside their corresponding DLLs.

    Second enable full data in the PDB files. Debug builds do this by default, but release builds do not include the line number information.

    Best regards,

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 19, 2015 1:23 AM