I am trying to get details from an exception occurred in my c# (4.0) asp.net web application. I have .pdb file in bin folder. The following code is not working as expected -
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//throwing Exception
using (SqlConnection connection=new SqlConnection(""))
{
connection.Open();
}
}
catch (Exception exception)
{
//Get a StackTrace object for the exception
StackTrace st = new StackTrace(exception, true);
//Get the first stack frame
StackFrame frame = st.GetFrame(0); //returns {PermissionDemand at offset 5316022 in file:line:column <filename unknown>:0:0}
//Get the file name
string fileName = frame.GetFileName(); //returns null
//Get the method name
string methodName = frame.GetMethod().Name; //returns PermissionDemand
//Get the line number from the stack frame
int line = frame.GetFileLineNumber(); //returns 0
//Get the column number
int col = frame.GetFileColumnNumber(); //returns 0
}
}
What is wrong here?
update: "StackFrame frame = st.GetFrame(st.FrameCount - 1); " solved this issue.