Debugging Dotnet Web Application

Discussion in 'ASP .Net Web Services' started by jpaquette@comloginc.com, Jan 10, 2005.

  1. Guest

    This may be an exercise in futility otherwise I would already have
    found the answer, but what the heck. Here's the scenario:

    I maintain a website programmed in C# using the .Net framework. I
    have the global asax file configured to grab the InnerException
    message and send me an email when an error is encountered on the site.
    This does a good job of telling me the page and type of problem, but
    in certain circumstances is utterly useless because I cannot find a
    way to produce the line number of the actual code where the error
    occured.

    I've already tried getting the info from the stacktrace but all I get
    is information from the asax file that is sending me the email (that
    is the stackframe.GetLineNumber returns the line in the asax where the
    stacktrace is referenced).

    I am researching this because I get a lot of "Object reference not
    found" errors. These errors occur on multiple pages and I cannot find
    the source of them. I'm persistantly unable to recreate the error
    myself. If I was able to configure the error alert emails to include
    the line numbers where this happens, I might be able to get rid of this
    error once and for all.

    If there is anyone out there in googleland that can sympathize with my
    plight and provide me with a nice explanation of how to do this or why
    it is not possible I would be most appreciative.
    , Jan 10, 2005
    #1
    1. Advertising

  2. erymuzuan Guest

    this works fine to me
    protected void Application_Error(Object sender, EventArgs e)
    {/* instantiate all the Exception class */
    System.Exception ex = Server.GetLastError();

    /* security Exception */
    if( this.HandleSecurityException( ex ))
    {
    /* redirect a user to a page */
    Response.Redirect( "~/UnAuthorizedRequest.aspx" );
    Response.End();
    Server.ClearError(); /* don't want to log this */
    return;
    }

    /* other exceptions */
    LogOtherException(ex);
    }

    private void LogOtherException(Exception e)
    {
    //
    // keep in session
    HttpContext.Current.Trace.Warn("Last Server Error", e.ToString());
    /* your error logging */
    MailMessage mail = new MailMessage();


    mail.BodyFormat = MailFormat.Text;
    mail.Body = "";
    mail.Body += Request.Url;
    mail.Body += "\n\n";
    mail.Body += "Message : \n";
    mail.Body += e.Message + "\n";
    mail.Body += "\n\n";
    mail.Body += "Source : \n";
    mail.Body += e.Source + "\n";
    mail.Body += "\n\n";
    mail.Body += "Stack Trace : \n";
    mail.Body += e.StackTrace;
    mail.Body += "\n\n";
    mail.Body += "Exeception.ToString() : \n";
    mail.Body += e.ToString();

    // send


    regards
    erymuzuan

    wrote:
    > This may be an exercise in futility otherwise I would already have
    > found the answer, but what the heck. Here's the scenario:
    >
    > I maintain a website programmed in C# using the .Net framework. I
    > have the global asax file configured to grab the InnerException
    > message and send me an email when an error is encountered on the site.
    > This does a good job of telling me the page and type of problem, but
    > in certain circumstances is utterly useless because I cannot find a
    > way to produce the line number of the actual code where the error
    > occured.
    >
    > I've already tried getting the info from the stacktrace but all I get
    > is information from the asax file that is sending me the email (that
    > is the stackframe.GetLineNumber returns the line in the asax where the
    > stacktrace is referenced).
    >
    > I am researching this because I get a lot of "Object reference not
    > found" errors. These errors occur on multiple pages and I cannot find
    > the source of them. I'm persistantly unable to recreate the error
    > myself. If I was able to configure the error alert emails to include
    > the line numbers where this happens, I might be able to get rid of this
    > error once and for all.
    >
    > If there is anyone out there in googleland that can sympathize with my
    > plight and provide me with a nice explanation of how to do this or why
    > it is not possible I would be most appreciative.
    >
    erymuzuan, Jan 10, 2005
    #2
    1. Advertising

  3. Hello ,
    Unfortunately you need to have the server code in debug mode to get line
    nos. However it should give you the last method called from which you could
    see what the potential problems could be

    HTH
    Regards,
    Dilip Krishnan
    MCAD, MCSD.net
    dkrishnan at geniant dot com
    http://www.geniant.com

    > This may be an exercise in futility otherwise I would already have
    > found the answer, but what the heck. Here's the scenario:
    >
    > I maintain a website programmed in C# using the .Net framework. I
    > have the global asax file configured to grab the InnerException
    > message and send me an email when an error is encountered on the site.
    > This does a good job of telling me the page and type of problem, but
    > in certain circumstances is utterly useless because I cannot find a
    > way to produce the line number of the actual code where the error
    > occured.
    > I've already tried getting the info from the stacktrace but all I get
    > is information from the asax file that is sending me the email (that
    > is the stackframe.GetLineNumber returns the line in the asax where the
    > stacktrace is referenced).
    >
    > I am researching this because I get a lot of "Object reference not
    > found" errors. These errors occur on multiple pages and I cannot find
    > the source of them. I'm persistantly unable to recreate the error
    > myself. If I was able to configure the error alert emails to include
    > the line numbers where this happens, I might be able to get rid of
    > this error once and for all.
    >
    > If there is anyone out there in googleland that can sympathize with my
    > plight and provide me with a nice explanation of how to do this or why
    > it is not possible I would be most appreciative.
    >
    Dilip Krishnan, Jan 10, 2005
    #3
  4. Guest

    Thanks for the help. I'll try it out and see how it works.
    , Jan 10, 2005
    #4
  5. Guest

    You'll need to forgive my ignorance. I tried the suggestion, but
    unfortunately trying to decode a stack trace for me is like trying to
    understand a foreign language. Usually I can debug things be getting a
    general sense of what the problem is through the error message and then
    looking at the line number where it was created to determine the
    malfunction. I'm not sure why the stack trace isn't configured to give
    this information. At any rate, here is the information I got from an
    artificial bug I created on the site using the suggestion above. If
    someone could give me pointers on how to read it, or what to look for
    then I would be grateful.

    Stack Trace :
    at System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean
    fCreateIfNotFound)
    at System.Web.UI.TemplateParser.GetParserCacheItem()
    at
    System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(String
    virtualPath, String inputFile, HttpContext context)
    at System.Web.UI.TemplateControlParser.GetCompiledInstance(String
    virtualPath, String inputFile, HttpContext context)
    at System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
    virtualPath, String inputFile, HttpContext context)
    at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context,
    String requestType, String url, String path)
    at System.Web.HttpApplication.MapHttpHandler(HttpContext context,
    String requestType, String path, String pathTranslated, Boolean
    useAppConfig)
    at
    System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    Boolean& completedSynchronously)

    Exeception.ToString() :
    System.Web.HttpException: External component has thrown an exception.
    ---> System.Web.HttpCompileException: External component has thrown an
    exception.
    at
    System.Web.Compilation.BaseCompiler.ThrowIfCompilerErrors(CompilerResults
    results, CodeDomProvider codeProvider, CodeCompileUnit sourceData,
    String sourceFile, String sourceString)
    at System.Web.Compilation.BaseCompiler.GetCompiledType()
    at System.Web.UI.PageParser.CompileIntoType()
    at
    System.Web.UI.TemplateParser.GetParserCacheItemThroughCompilation()
    --- End of inner exception stack trace ---
    at System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean
    fCreateIfNotFound)
    at System.Web.UI.TemplateParser.GetParserCacheItem()
    at
    System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(String
    virtualPath, String inputFile, HttpContext context)
    at System.Web.UI.TemplateControlParser.GetCompiledInstance(String
    virtualPath, String inputFile, HttpContext context)
    at System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
    virtualPath, String inputFile, HttpContext context)
    at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context,
    String requestType, String url, String path)
    at System.Web.HttpApplication.MapHttpHandler(HttpContext context,
    String requestType, String path, String pathTranslated, Boolean
    useAppConfig)
    at
    System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    Boolean& completedSynchronously)
    , Jan 11, 2005
    #5
  6. Hello ,
    Seems like yr having an ASP.net UI problem not a web service problem.
    What a stack trace is .. is a heirarchy of methods that are called until
    the error occurs


    HTH
    Regards,
    Dilip Krishnan
    MCAD, MCSD.net
    dkrishnan at geniant dot com
    http://www.geniant.com

    > You'll need to forgive my ignorance. I tried the suggestion, but
    > unfortunately trying to decode a stack trace for me is like trying to
    > understand a foreign language. Usually I can debug things be getting
    > a general sense of what the problem is through the error message and
    > then looking at the line number where it was created to determine the
    > malfunction. I'm not sure why the stack trace isn't configured to
    > give this information. At any rate, here is the information I got
    > from an artificial bug I created on the site using the suggestion
    > above. If someone could give me pointers on how to read it, or what
    > to look for then I would be grateful.
    >
    > Stack Trace :
    > at System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean
    > fCreateIfNotFound)
    > at System.Web.UI.TemplateParser.GetParserCacheItem()
    > at
    > System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(Strin
    > g
    > virtualPath, String inputFile, HttpContext context)
    > at System.Web.UI.TemplateControlParser.GetCompiledInstance(String
    > virtualPath, String inputFile, HttpContext context)
    > at System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
    > virtualPath, String inputFile, HttpContext context)
    > at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context,
    > String requestType, String url, String path)
    > at System.Web.HttpApplication.MapHttpHandler(HttpContext context,
    > String requestType, String path, String pathTranslated, Boolean
    > useAppConfig)
    > at
    > System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecuti
    > onStep.Execute()
    > at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    > Boolean& completedSynchronously)
    > Exeception.ToString() :
    > System.Web.HttpException: External component has thrown an exception.
    > ---> System.Web.HttpCompileException: External component has thrown an
    > exception.
    > at
    > System.Web.Compilation.BaseCompiler.ThrowIfCompilerErrors(CompilerResu
    > lts
    > results, CodeDomProvider codeProvider, CodeCompileUnit sourceData,
    > String sourceFile, String sourceString)
    > at System.Web.Compilation.BaseCompiler.GetCompiledType()
    > at System.Web.UI.PageParser.CompileIntoType()
    > at
    > System.Web.UI.TemplateParser.GetParserCacheItemThroughCompilation()
    > --- End of inner exception stack trace ---
    > at System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean
    > fCreateIfNotFound)
    > at System.Web.UI.TemplateParser.GetParserCacheItem()
    > at
    > System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(Strin
    > g
    > virtualPath, String inputFile, HttpContext context)
    > at System.Web.UI.TemplateControlParser.GetCompiledInstance(String
    > virtualPath, String inputFile, HttpContext context)
    > at System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
    > virtualPath, String inputFile, HttpContext context)
    > at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context,
    > String requestType, String url, String path)
    > at System.Web.HttpApplication.MapHttpHandler(HttpContext context,
    > String requestType, String path, String pathTranslated, Boolean
    > useAppConfig)
    > at
    > System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecuti
    > onStep.Execute()
    > at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    > Boolean& completedSynchronously)
    Dilip Krishnan, Jan 12, 2005
    #6
  7. Guest

    This is the actual stack trace of the live error. Interestingly, I've
    noticed that all the errors on the site produce the same stack trace.
    I wonder if the cause of that has something to do with the way I've got
    my error reporting set up.

    Exception Stack Trace:
    ----------------------
    at System.Web.UI.Page.HandleError(Exception e)
    at System.Web.UI.Page.ProcessRequestMain()
    at System.Web.UI.Page.ProcessRequest()
    at System.Web.UI.Page.ProcessRequest(HttpContext context)
    at
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    Boolean& completedSynchronously)
    , Jan 12, 2005
    #7
  8. Hello ,

    Doest appear like your hitting any of your own code in the stack trace.
    What are you trying to do when you get this error.
    HTH
    Regards,
    Dilip Krishnan
    MCAD, MCSD.net
    dkrishnan at geniant dot com
    http://www.geniant.com

    > This is the actual stack trace of the live error. Interestingly, I've
    > noticed that all the errors on the site produce the same stack trace.
    > I wonder if the cause of that has something to do with the way I've
    > got
    > my error reporting set up.
    > Exception Stack Trace:
    > ----------------------
    > at System.Web.UI.Page.HandleError(Exception e)
    > at System.Web.UI.Page.ProcessRequestMain()
    > at System.Web.UI.Page.ProcessRequest()
    > at System.Web.UI.Page.ProcessRequest(HttpContext context)
    > at
    > System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecut
    > ionStep.Execute()
    > at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
    > Boolean& completedSynchronously)
    Dilip Krishnan, Jan 12, 2005
    #8
  9. Guest

    I'm not sure what I'm trying to do when I get the error because I don't
    know where the error is occuring. The first stack trace that I posted
    was generated by removing the ";" punctuation from a line of code. The
    second one (the one you're referring to) is generated from time to time
    by the website I manage. The Inner Exception message tells me that I
    have an object reference not set to an instance of an object. The
    problem is that this error occurs all over the place and I can't
    identify the circumstances under which it occurs so I'm having a hard
    time figuring out just what is happening when this occurs. Looking at
    the stack trace further I'm starting to think I don't have my error
    reporting set up right because it looks like its giving me data from
    what it's trying to do when it reports the error, not what actually
    happened when the error occured.
    , Jan 12, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,320
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    527
    SpamProof
    Oct 21, 2003
  3. Chuck
    Replies:
    3
    Views:
    491
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 8, 2007
  4. J. Paquette

    Debugging Dotnet Web Application

    J. Paquette, Sep 1, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    105
    J. Paquette
    Sep 1, 2004
  5. Debugging Dotnet Web Application

    , Apr 28, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    123
Loading...

Share This Page