Tip: Shadow Copy and your bin directory

One of the things that makes developing ASP.NET applications very cool is that you can rapidly prototype, tweak, and update your application, without having to stop and restart the web server. This includes assemblies (DLLs) used by your application for things like business logic and/or data access. You can simply drag and drop a new copy of a DLL into the \bin directory, and ASP.NET will automatically start using the new DLL with the next request.

The way that this works is that ASP.NET makes a shadow copy of the contents of the \bin directory, and loads the DLLs from the copy. ASP.NET monitors the \bin directory for changes, and repeats the shadow copy when the contents change.

While this is very convenient, it does take time, and if you have a large number of DLLs, or very large DLLs, the shadow copy process can potentially impact application startup and restart performance. This is also true if you have non-dll content in the \bin directory (a good reason never to store anything but DLLs in \bin).

So in some situations, you might want to turn off the shadow copy process. To do this, add the following to your ASP.NET 2.0 web.config file:

<hostingEnvironment shadowCopyBinAssemblies="false" />

While this will reduce performance overhead associated with shadow copying the contents of the \bin directory, do keep in mind that using this configuration option will result in the DLLs being locked when the app is running. So if you need to update a DLL, you will need to take the application offline or stop the process before you can do so.

[hat tip to Scott Guthrie, who originally shared this tip via email]