none
Virtual Path Provider giving "Directory 'E:\sitesroot\0\xxx' does not exist. Failed to start monitoring file changes"

    Question

  • In my application start I have the following line:

    HostingEnvironment.RegisterVirtualPathProvider(new VirtualServicePathProvider("/Services"));

     Which basically says, hey any request made to a file inside "~/Services" should be handled by this virtual path provider. I then generate an SVC file and go download the service assembly (a ZIP file in BLOB storage) and load it into the app domain.

    This all works brilliantly on premise AND in the development fabric but throws an error when deployed to Windows Azure. Just throwing this out there to see if I am doing anything that immediately pops out to anyone as non-Azure friendly.

    Thursday, July 14, 2011 12:15 PM

Answers

  • Hi Markti,

    I cannot think of a reason that Azure may cause this exception. It seems to be thrown by your own code that it uses FileSystemWatcher Class to monitor a directory without checking its existence. One possible cause is that, as you are using your own virtual path to access svc files, HttpServerUtility.MapPath Method may return an incorrect value.

    For example, a svc file is in [siteroot]\myfiles\test.svc folder but it is accessed via a virtual path http://domain/services/test.svc. If the svc file calls HttpContext.Current.Server.MapPath("subfolder")  to get the physical path of a folder, it get the value [siteroot]\services\subfoler (which does not exist) instead of the expected one [siteroot]\myfiles\subfolder.

    Related resources:

    FIX: Exception error message when you use a virtual path provider to serve a Web page that has a ScriptManager control: "Directory '<file directory>' does not exist. Failed to start monitoring file changes."
    http://support.microsoft.com/kb/957661

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by Wenchao Zeng Thursday, July 21, 2011 5:58 AM
    Friday, July 15, 2011 7:29 AM

All replies

  • Hi Markti,

    I cannot think of a reason that Azure may cause this exception. It seems to be thrown by your own code that it uses FileSystemWatcher Class to monitor a directory without checking its existence. One possible cause is that, as you are using your own virtual path to access svc files, HttpServerUtility.MapPath Method may return an incorrect value.

    For example, a svc file is in [siteroot]\myfiles\test.svc folder but it is accessed via a virtual path http://domain/services/test.svc. If the svc file calls HttpContext.Current.Server.MapPath("subfolder")  to get the physical path of a folder, it get the value [siteroot]\services\subfoler (which does not exist) instead of the expected one [siteroot]\myfiles\subfolder.

    Related resources:

    FIX: Exception error message when you use a virtual path provider to serve a Web page that has a ScriptManager control: "Directory '<file directory>' does not exist. Failed to start monitoring file changes."
    http://support.microsoft.com/kb/957661

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by Wenchao Zeng Thursday, July 21, 2011 5:58 AM
    Friday, July 15, 2011 7:29 AM
  • Hi,

    I will mark the reply as answer. If you find it no help, please feel free to unmark it and follow up.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Thursday, July 21, 2011 5:58 AM
  • Just found a solution after having an exact same issue. The trick is to override cache dependency in VirtualFile. In VirtualPathProvider override method GetCacheDependency like so:

     

            public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)

            {

                return IsPathVirtual(virtualPath) ? null : base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);

            }

     

    The IsPathVirtual checks if the path is one of the embedded resources. It's where you would check if virtual path points to "/Services" This way any other (physical) files are cached and directory monitored for changes.

    PS: I Only found this by looking at exception stack trace and seeing it was getting a cache dependency.

     

    Hope this helps.


    Think about the box
    Wednesday, August 10, 2011 3:00 PM
  • Hi,

    I just wanted to let you know about this related issue:

    I was receiving a parser error saying "Directory 'xxx' does not exist. Failed to start monitoring file changes". The parser error was pointed at a Register directive inside an .ascx file. Both the ascx file and target of the Register directive were served via a custom VirtualPathProvider.

    Overriding GetCacheDependency solved the issue.

    Friday, July 27, 2012 11:01 AM