title: Assembly FileLoadException (Access is denied) after period of time
body: <p>I have a web application that works fine for a while (a few days) and then starts throwing FileLoadException's when instantiating a class that references an external dll.</p>
  
  <ul>
  <li>I'm not explicitly loading the assembly with any of the Assembly static methods. I'm just instantiating a class that itself instantiates a class from the referenced library.</li>
  <li>I ran Process Monitor and just monitored the application path. I only get "PATH NOT FOUND" results for the source code file where the error occurs (compiled in debug mode so I assume this is just part of .NET trying to show the line where the error occurred when dumping the stack trace)</li>
  <li>This is running on a dedicated server in-house. The application is running on a .NET 3.5 application pool along with another web site built using the same referenced dll's. The other web site has a lot more traffic but never gets this error.</li>
  <li>The application is load-balanced across 3 web servers and all 3 get this issue at some point.</li>
  </ul>
  
  <p>I turned on assembly binding logging on one of the web servers. Here is what the stack trace looks like:</p>
  
  <pre><code>System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---&gt; System.IO.FileLoadException: Could not load file or assembly 'Project.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.
  File name: 'Project.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
     at ...
     at System.Web.UI.Control.OnLoad(EventArgs e)
     at System.Web.UI.Control.LoadRecursive()
     at System.Web.UI.Control.LoadRecursive()
     at System.Web.UI.Control.LoadRecursive()
     at System.Web.UI.Control.LoadRecursive()
     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  
  Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
  Running under executable  c:\windows\system32\inetsrv\w3wp.exe
  --- A detailed error log follows. 
  
  === Pre-bind state information ===
  LOG: User = Unknown
  LOG: DisplayName = Project.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
   (Fully-specified)
  LOG: Appbase = file:///C:/websites/ProjectPath/
  LOG: Initial PrivatePath = C:\websites\ProjectPath\bin
  Calling assembly : WebApp, Version=1.0.3723.37743, Culture=neutral, PublicKeyToken=null.
  ===
  LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\websites\ProjectPath\web.config
  LOG: Using host configuration file: \\?\c:\windows\microsoft.net\framework\v2.0.50727\aspnet.config
  LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
  LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
  LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/d77c161e/8751390/Project.Library.DLL.
  LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/d77c161e/8751390/Project.Library/Project.Library.DLL.
  LOG: Attempting download of new URL file:///C:/websites/ProjectPath/bin/Project.Library.DLL.
  ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated.
  
     --- End of inner exception stack trace ---
     at System.Web.UI.Page.HandleError(Exception e)
     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
     at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
     at System.Web.UI.Page.ProcessRequest()
     at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
     at System.Web.UI.Page.ProcessRequest(HttpContext context)
     at ASP.myaccount_home_aspx.ProcessRequest(HttpContext context)
     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
  </code></pre>
  
  <p>I'm not very familiar with debugging file load exceptions, so any help is greatly appreciated (what else I can do to debug, etc.).</p>
  
  <p>Thanks.</p>