Skip to content

Intuitive Microsoft Exception Messages…

I’m developing a web application which takes advantage of Microsoft Enterprise Library’s Logging block to log Errors in a custom sink I’ve developed. Now in order to log unhandled exceptions I’ve hooked on the Application_Error event of the HttpApplication object, the code looks something like that:


void application_Error(object sender, EventArgs e)


{


  HttpApplication app = (HttpApplication)sender;


  Exception error = app.Server.GetLastError();


  if (error != null)


  {


    LogEntry errorEntry = new LogEntry();


    errorEntry.Title = error.Message;


    errorEntry.Categories.Add(“General”);


    errorEntry.EventId = (int)(LoggingErrorCodes.Unhandled_Error);


    errorEntry.Severity = System.Diagnostics.TraceEventType.Error;


    errorEntry.ExtendedProperties.Add(“CallStack”, error.StackTrace);


    Logger.Write(errorEntry);


    app.Server.ClearError();


  }


}


So far so good, when I run the application though, I was getting an exception for almost every request made, which resulted of course in a log entry beeing written on the log. The exception had the intuitive message “File does not exist.” , the exception type was HttpException and the call stack indicated that the exception was originating from the ProcessRequestInternal method of HttpStaticHandler class. Finally the page was loading up fine (no obvious errors).
Ok here is the trivia question (don’t read bellow before answering that ;-)) can you imagine why this was happening?


After spending a couple of hours on that and doing a little disassembling on the HttpStaticHandler class (sorry MS had no other way) I’ve discovered that a file was actually missing and that’s why I was getting the exception,


internal static void ProcessRequestInternal(HttpContext context)


{


  HttpRequest request1 = context.Request;


  HttpResponse response1 = context.Response;


  string text1 = request1.PhysicalPath;


  if (!HostingEnvironment.UsingMapPathBasedVirtualPathProvider)


  {


    StaticFileHandler.RespondUsingVirtualFile(request1.FilePath, response1);


  }


  else


  {


    FileInfo info1;


    if (!FileUtil.FileExists(text1))


    {


      throw new HttpException(0x194, SR.GetString(“File_does_not_exist”));


    }



But which file? Once more the page I was requesting was loading up fine. Can you, after these clues, imagine what was going on?


If you still don’t know, here is the solution to the trivia. I’ve put a watch on the ((HttpApplication)sender).context.Request object and set a breakpoint in the application error event handler. From the Request object I found out that the blank.gif (from the name you can see why I was seeing no difference on the page) was missing from a javascript component that was trying to load it at runtime.

If only the guy who wrote the ProcessRequestInternal method of the HttpStaticHandler class had added the text1 local variable in the exception information it would have saved me a lot of time and efford from trying to find out the error. So the lesson learned here is “Always include helpful information to your exceptions” it will make the life of other developers a lot easier…

Published inASP.NET

7 Comments

  1. Hi,

    Thanks for your post but I don”t understand exactly what the problem is. I”m seeing the same exact behavior in my ASP 2.0 web application. Also, what is the solution? Is there a way to stop this “File does not exist.” exception being thrown?

    -Andy

    Here’s a log entry from my error log:

    ———–HEADER—————–

    Timestamp: 7/29/2006 8:54:51 AM

    Message: HandlingInstanceID: 97ae3d7c-1348-41c0-a0b7-c00994f12e54

    An exception of type ”System.Web.HttpException” occurred and was caught.

    ————————————————————————

    07/29/2006 01:54:51

    Type : System.Web.HttpException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

    Message : File does not exist.

    Source : System.Web

    Help link :

    ErrorCode : -2147467259

    Data : System.Collections.ListDictionaryInternal

    TargetSite : Void ProcessRequestInternal(System.Web.HttpContext)

    Stack Trace : at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)

    at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)

    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    Additional Info:

    MachineName : ANDEEZLE

    TimeStamp : 7/29/2006 8:54:51 AM

    FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null

    AppDomainName : b4b741ac-18-127986358293125000

    ThreadIdentity : ANDEEZLEAndy

    WindowsIdentity : ANDEEZLEAndy

    Category: WebAppTrace

    Priority: 0

    EventId: 100

    Severity: Error

    Title:WebApp Policy — Enterprise Library Exception Handling

    Machine: ANDEEZLE

    Application Domain: b4b741ac-18-127986358293125000

    Process Id: 1404

    Process Name: C:WINDOWSMicrosoft.NETFrameworkv2.0.50727WebDev.WebServer.EXE

    Win32 Thread Id: 3472

    Thread Name:

    Extended Properties:

    ———–FOOTER—————–

  2. Leonard Leonard

    Andy,

    He”s saying you need to get the name of the file from within your handler in Global.asax.cs

    void Application_Error(Object sender, EventArgs e)

    {

    //Set breakpoint here

    LogErrorRoutine(this.Server);

    }

    And then add a watch on

    ((HttpApplication)sender).Context.Request

    The request will show you the file that does not exist on your server.

    But to stop the error, you have to know what file is missing. Either supply the file or remove whatever is calling it.

    Hope that helps,

    Leonard

  3. Aimee Couturier Aimee Couturier

    This post was very helpful! Thanks

  4. Joe Joe

    I”m getting the same error, and it”s getting really annoying having to wade through all these entries when I need to debug my application. Your article gave me direction on how to find and remove this error… the only problem now is to find which file it is that”s causing the problem. Do you have any tips on how to go about doing this?

    Thanks.

  5. Have you tried putting a watch on the application context inside the Application_Error event handler on Global.asax as mentioned earlier?
    I think if you do what Aimee suggested you ”ll be able to find which file is causing the exception.

    HTH

  6. Ben Ben

    Excellent post, this led me directly to the offending file. Setting the watch on ((HttpApplication)sender).Context.Request is the key to finding the problem

  7. it’s interesting to note that while Microsoft didn’t end up using the ribbon in their professional products, such as Project — perhaps because of the negative user feedback. I like the ribbon in Office, but I find many advanced commands difficult to find, after years of habit, one exception is the options dialogue which hidden under the office button is nigh-impossible to find — it seems Office 2010 could be a step in the right direction.

Leave a Reply to Ben Cancel reply

Your email address will not be published.