Excessive recompilations when using VirtualPathProvider

This is a quick pointer for anyone implementing a VirtualPathProvider in their ASP.NET applications. I’ve read a number of tutorials on VPPs but none really touched on this issue.

If you do not implement a method for VirtualPathProvider.GetFileHash(...), calls to this method will return null/Nothing.

If this happens, ASP.NET’s build/compile system doesn’t remember that it has already compiled the file and attempts to do so again. After 15 compiles, the AppDomain is unloaded and the application restarts. This can cause major irritation, particularly with performance, as the recompiles take time.

To get around it in my app, I am overriding GetFileHash to return a string concatenation of the VirtualFile’s name and Last Modified Date. If anyone knows of a better hash, then please let me know.

Advertisements

2 Responses to “Excessive recompilations when using VirtualPathProvider”

  1. chinmay Says:

    im also facing same issue….
    any solution??
    please reply

  2. jimbobmcgee Says:

    I’ve had two issues with recompilation recently: one was the above, which I fixed by implementing GetFileHash(…) to return a concatenation of the filename and last modified date; the other was due to a log file located in the bin folder — every time the log file changed, the bin folder ‘changed’ and ASP.NET’s in-built FileSystemWatcher caught the change and triggered a recompilation.

    Hope this helps.

    J.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: