title: IIS pool recycle, pool restart, app restart, web.config update - global asax
body: <p>I have MVC3 web application running under IIS 7. During initialization in global.asax application scans all the assemblies returned by BuildManager.GetReferencedAssemblies(), and all the types (Assembly.GetTypes()) in those assemblies in order to do initialization stuff. </p>
  
  <p>From time to time the application stops working properly - it behaves as if the initialization never happened or some types were omited during startup. Once the application enters this failed state (I think it happens after the pool is recycled) it stays that way until restarted by:</p>
  
  <ol>
  <li>Manual updating Web.Config (adding some spaces)</li>
  <li>Manual restarting Application in IIS Manager</li>
  <li>Manual stopping and starting application pool in IIS Manager</li>
  <li>Automatic pool recycle</li>
  </ol>
  
  <p>I noticed that 1. always helps, but 2,3,4 works indeterministically - at least as far as I can say because the nature of the problem is not deterministic - application crashes only after some scheduled recycles.
  What is the difference between 1 and 2,3,4 from the point of view of global.asax code and access to loaded assemblies?</p>
  
  <p>Oh, the application runs as a sub-application (subfolder in IIS sites tree) if it changes anything.</p>