I have a .Net web application where any uncaught exceptions get handled via the Application_Error event in Global.asax. Here, I email myself details of any uncaught exceptions that sneak through.
My problem is that while I am getting the error messages just fine, I am not getting the line numbers in the stack trace to denote where the error is happening.
The Application_Error code is as follows:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Error
' Fires when an error occurs
Dim Context As System.Web.HttpContext = HttpContext.Current
Dim Ex As System.Exception = Context.Server.GetLastError.GetBaseException
Dim Path As String = Context.Current.Request.Url.AbsolutePath
Try
objMailMessage.From = "..." : objMailMessage.To = "..."
objMailMessage.Subject = "Global Error - " & System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath)
objMailMessage.Body = Ex.Message & "<BR>" & Ex.Source & "<BR>" & Ex.StackTrace & "<BR>" & Ex.TargetSite.Name
Finally
objSmtpMail.Send(objMailMessage)
objSmtpMail = Nothing
End Try
Context.Server.ClearError()
End Sub
The specific error email I'm getting is:
Input string was not in a correct format.
mscorlib
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Web.UI.WebControls.ImageButton.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
StringToNumber
Of note, I already have the PDB file in the bin folder, as well as have debug set to true in my web.config. Also, this web app was built in Visual Studio 2003, and is running in a .Net 4.0 app pool in IIS 7.5.
Am I doing something wrong in trying to obtain fully detailed error messages, with line numbers, etc? Thanks in advance for any insight you can provide.