Mike
Mike

Reputation: 6239

File Does Not Exist Exception in VS2010

I've taken over the code of a website from someone else to finish off and have hit the issue that every time I load a page, I get a 'File Does Not Exist' exception caught in the Application_Error handler in my Global.asax file.

I was curious what it was, so have tried creating brand new solutions with both a Web Site and Web Application, both with and without a Master Page and a single .aspx page - both had the same problem.

This is using VS2010 and .NET 3.5, on Windows 7 64-bit.

Any ideas please? The stack trace tells me absolutely nothing and the fact I'm getting it with new projects is odd.

Exception Stack Trace:

at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
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)

Upvotes: 9

Views: 6035

Answers (5)

Rob Ainscough
Rob Ainscough

Reputation: 618

I solved this for my situation ... turned out that the project properties had reverted back to "Use Current Page" (in VS 2010 - Project Properties | Start Options | Start Action).

The odd thing is that I had set the Start Options to "Specific Page:" -- so somewhere along the line VS 2010 lost track of it and defaulted back to "Use Current Page".

Rob.

Upvotes: 1

Brian Gideon
Brian Gideon

Reputation: 48949

The trick in figuring out which file does not exist is to use the following code in the Application_Error method.

protected void Application_Error(Object sender, EventArgs e)
{
  Exception ex = Server.GetLastError().GetBaseException();
  string file = HttpContext.Current.Request.Url.ToString();
  string page = HttpContext.Current.Request.UrlReferrer.ToString(); 
}

This will retrieve the name of the file that is missing and the original page from which the request came.

Upvotes: 10

sigi
sigi

Reputation: 153

I detect my error in Application_Error within gloal.asax I also get Request.Url.ToString(), this would give you the culprit resource. For example in my app I found that the Application_Error even complains about the favicon.ico, and also if you have some files missing that you might be referencing from your css, it would get caught by the Application_Error event.

actually, check out this blog for example, talks about the same issue and using the Request.Url to discover what the resource in question is. This should help http://dotbert.loedeman.nl/httpexception-file-does-not-exist

Upvotes: 2

Mike
Mike

Reputation: 6239

I never got to the bottom of this sadly and an overdue rebuild of my computer sorted it.

Upvotes: 1

Cylon Cat
Cylon Cat

Reputation: 7201

What is the file name in the exception? If the file name or the path is obfuscated, then you likely have a corruption in ASP.NET temporary files. Try "clean solution" and "rebuild solution" and run it again.

Otherwise, you'll need to post more information, including the full exception message, not just the call stack. Is this happening on the default page of the site? Is the web project selected as the startup project? Is this happening in the Visual Studio web server, or IIS?

Upvotes: 3

Related Questions