Debugging Dotnet Web Application

J

jpaquette

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.
 
E

erymuzuan

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
 
D

Dilip Krishnan

Hello (e-mail address removed),
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
 
J

jpaquette

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)
 
D

Dilip Krishnan

Hello (e-mail address removed),
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
 
J

jpaquette

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)
 
D

Dilip Krishnan

Hello (e-mail address removed),

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
 
J

jpaquette

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top