December 2012 Blog Posts
Rip Page Inspector out of your Web Site Projects now

Page Inspector causing multiple calls to HttpApplication : Application_Start in Web Site Projects

image

I had a mysterious problem receiving multiple calls to Application_Start on almost every HTTP request to IISExpress. Upon further investigation, I found Visual Studio 2012's Page Inspector causing the problem.

Inside the default machine's Web.config located at: Windows\Microsoft.NET\Framework\v4.0.30319\Config, XPath: \System.Web\compilation\assemblies has an assembly "Microsoft.VisualStudio.Web.PageInspector.Loader", which dynamically loads itself via [assembly: PreApplicationStartmethod(typeof(RuntimeLoader),"PreApplicationStart"] attribute.

The ASP.NET BuildManager's hash of the compiled web site project kept changing upon the first & subsequent request to IISExpress. Somehow the dynamically loaded PageInsepctor.Runtime caused the HttpApplication to shutdown, startup, in an oscillating fashion (hence, the mulitiple Application_Start calls) as requests were being processed. Specifically, Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.
    SelectionMappingExecutionListenerModule.PreApplicationStart
()'s call to BuildManager.AddCompilationDependency() caused root compilation hash to change.

Disabling and removing Microsoft's Page Inspector feature removed the restarting interference. Here's how to remove the entire feature from your project:

Disable Visual Studio 2012 Page Inspector

To disable visual studio Page Inspector remove the assembly inside your Web.config located in configuration/compilation/assemblies:

Code Snippet
  1. <compilation debug="true" targetFramework="4.5">
  2.   <assemblies>
  3.     <remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader,
                          Version=1.0.0.0, Culture=neutral,
                          PublicKeyToken=b03f5f7f11d50a3a"
    />
  4.   </assemblies>
  5. </compilation>

Alternatively, you can add this to your appSettings:

Code Snippet
  1. <appSettings>
  2.   <add key="PageInspector:ServerCodeMappingSupport" value="Disabled" />
  3. </appSettings>

Hope that helps,
Brian Chavez