20

I have a .net app that I just opened on in visual studio 2010 and converted to 4.0 when it asked me on start-up. I go to try to build the site, and I get this error:

Failed to map the path '/'.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

[InvalidOperationException: Failed to map the path '/'.]
   System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +8804446
   System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) +42
   System.Web.VirtualPath.MapPathInternal() +4
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +107
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath) +37
   System.Web.HttpServerUtility.MapPath(String path) +99
   NU.WorkManagement.Lookup.Lookups..ctor() +82
   NU.WorkManagement.Engine.GlobalModule.Init(HttpApplication application) +624
   System.Web.HttpApplication.InitModulesCommon() +80
   System.Web.HttpApplication.InitModules() +43
   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +828
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +304
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +327

I tried the most popular solution I found vis google (replace and ../ with ~/ but there wern't any...)

Update:

Lookups constructor:

public Lookups()
{           
    _dirPath = System.Web.HttpContext.Current.Server.MapPath("/") + _xmlPath;           
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
kralco626
  • 8,456
  • 38
  • 112
  • 169
  • Do you have a default document setup? Have you setup routes? – Oded Apr 01 '11 at 12:44
  • Can you post the constructor for the `Lookups` class? There's obviously something wrong being mapped. What web server are you running this on? Is this under a virtual directory? If you're running using the built in web server to VS, are you running VS as an administrator? – TheCloudlessSky Apr 01 '11 at 12:48
  • I am running using the built in web server to VS, yes i am running as admin. I firgured I would answer those two questions will I went to find the lookups class. – kralco626 Apr 01 '11 at 12:49
  • I don't know what a default document setup is, or routes... – kralco626 Apr 01 '11 at 12:50
  • Did you end up locating the source for the `Lookups` class? – TheCloudlessSky Apr 01 '11 at 13:24
  • Yes. I acutually had it referenced as a dll. I removed the dll and I no longer get this error (although I get some other errors, but thats a different issue). However, I'll post the code... – kralco626 Apr 01 '11 at 14:02
  • Is the current HttpContext what you're expecting? – Will Dean Apr 01 '11 at 14:04
  • @Will - I honestly have no idea, i didn't right the lookup component – kralco626 Apr 01 '11 at 14:55

4 Answers4

49

I know it's and old question, but for the record if you are running against IIS then

'iisreset' in the console may help resolving "Failed to map the path '/'." issue. I had this problem after renaming the sites in IIS.

tymtam
  • 31,798
  • 8
  • 86
  • 126
12

I was just trying to go through an exercise in a Microsoft Step By Step book and I hit this problem when trying to precompile an ASP.NET appliction.

Here's how I got past this - and it took me a day to figure out!

When you open the Visual Studio Command Prompt to do your build/precompile, you must right-click and choose "Run As Administrator".

That's all it took for me when trying to run this aspnet_compiler -v DeployThis C:\DeployThis -f -u

Greg Barth
  • 173
  • 1
  • 4
  • 12
5

Try System.Web.HttpContext.Current.Server.MapPath("~/"). Notice the ~.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
4

We had the same problem, IISRESET didn't do it. It turned out that the Virtual Directory we trying to map has a double backslash (d:\folder\\subfolder\) in the naming (IIS virtual directory was created with powershell script). Removing the extra backslash made HostingEnvironment.MapPath stop throwing exceptions.

Just in the case this could help somebody :-)

Henrik Stenbæk
  • 3,982
  • 5
  • 31
  • 33