I want to get line number of code which cause error. For example;
static void Main(string[] args) { using (SqlConnection conn = new SqlConnection(bagcum)
You might get 0 in result if you don't initialize StackTrace to include fileinfo.
Try this
try { //code } catch (Exception e) { var lineNumber = new System.Diagnostics.StackTrace(e, true).GetFrame(0).GetFileLineNumber(); }
This worked for me.