Recently, I ran into issues while writing an ASP.NET 4.0 application. I tried to remember if I had meddled with anything or deleted any components by mistake.

This was the error I get when trying to compile my application:

Could not load file or assembly 'Microsoft.VisualStudio.Web.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Below is the exception message seen in the browser:

Server Error in '/WebSite4' Application.
-----------------------------------------------------------------------------------------------------------------
Could not load file or assembly 'Microsoft.VisualStudio.Web.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Description
: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details
: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Web.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Web.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.VisualStudio.Web.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +57
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
   System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677

[HttpException (0x80004005): Could not load file or assembly 'Microsoft.VisualStudio.Web.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9036040
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

I couldn’t remember doing any such destructive activity.

I tried a couple of troubleshooting steps, I changed the target framework to .NET 3.5 and I was able to compile my application successfully. So, obviously the issue was with ASP.NET 4.0 applications only.

I started searching forums to see if someone had encountered this issue. Looks like I was not the only one. Smile

Seems the issue was due to a component called “Microsoft Page Inpector - Visual Studio vNext

Forum Link: http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/92823976-be85-43af-9efa-6b28f441fd6b/ 

Supposedly, Page Inspector on Visual Studio 2010 (RTM or SP1) will cause this problem. Page Inspector is only supported on the Visual Studio 11 Developer Preview, because it requires new components that only exist in ASP.NET 4.5.

Page Inspector's installer is supposed to block if you don't have the Developer Preview installed, but apparently that's not happening. I remember installing this component via Web Platform installer.

Don’t ask me the reason why I installed it, I just did it. Winking smile

So, the resolution was to uninstall this component.

  1. Go to "Programs and Features"
  2. Type "Page Inspector" and bingo, this would list it. It is listed as "Microsoft Page Inspector - Visual Studio vNext"
  3. Uninstall the component.

As soon as I uninstalled the component, the error went away. Relief! Smile

Out of curiosity, I tried installing it again via the Web Platform Installer, looks like it does prompt the user for a warning message before installing it.

image

I wonder if this prompt was thrown earlier. Anyways, this is fixed for now.

Until then, CYA Smile