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.

Are you writing the code in a script tag or in a code behind page?

Looks like a dynamically added image button is not posting back?

Hi thanks for the reply guys.

As it turns out, the actual problem wasnt really related to exception handling. Apparently there are problems with .Net 4.0 and Internet Explorer 10, specifically with regards to Image Buttons, and I believe javascript as well. I think .Net 2.0 also may have issues.

See: http://connect.microsoft.com/VisualStudio/feedback/details/755419/asp-net-4-0-and-ie10-click-on-imagebutton-in-updatepanel-produces-error-click-on-normal-button-does-not

Hotfix available here: http://www.microsoft.com/en-us/download/details.aspx?id=39257

I applied the hotfix on my server about an hour ago, and it appears to no longer be a problem on IE 10 for myself. Will continue to monitor throughought the day to ensure outside IE 10 users dont have problems any more as well.

Will update if there are any further issues. Thanks again!

Yes ... big problem when IE10 came out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.